Skip to content

Conversation

@claudiogodoy99
Copy link
Contributor

Hi team,

This PR adds a concrete example showing how to properly register and use the OpenAIClient with dependency injection in an ASP.NET Core application. It also includes a short highlighted section in the main README.md under the heading "How to use dependency injection".

PR for issue #498

@jsquire
Copy link
Collaborator

jsquire commented Jul 2, 2025

Thanks for your contribution, @claudiogodoy99, and your interest in improving the OpenAI developer experience. We'll take a look and see if we can get this merged in!

@jsquire
Copy link
Collaborator

jsquire commented Jul 2, 2025

@scottaddie, @achandmsft: Would appreciate your thoughts on sample content and docs organization.

@jsquire jsquire self-requested a review July 2, 2025 00:35
@claudiogodoy99
Copy link
Contributor Author

hey @jsquire, thanks for reviewing, I've made some commits addressing the comments.

Copy link
Collaborator

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @claudiogodoy99! A couple of minor nits, and I think we're good to merge.

Copy link
Collaborator

@jsquire jsquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thansk, @claudiogodoy99! I'll get this merged in.

@jsquire
Copy link
Collaborator

jsquire commented Jul 17, 2025

Hrmm... seeing a compile error in the pipeline. Unsure if we're missing some usings or the CI environment is misbehaving.

Error: /home/runner/work/openai-dotnet/openai-dotnet/examples/aspnet-core/Program.cs(47,18): error CS0246: The type or namespace name 'Task<>' could not be found (are you missing a using directive or an assembly reference?) [/home/runner/work/openai-dotnet/openai-dotnet/examples/OpenAI.Examples.csproj]
Error: /home/runner/work/openai-dotnet/openai-dotnet/examples/aspnet-core/Program.cs(38,22): error CS0246: The type or namespace name 'ILogger<>' could not be found (are you missing a using directive or an assembly reference?) [/home/runner/work/openai-dotnet/openai-dotnet/examples/OpenAI.Examples.csproj]
Error: /home/runner/work/openai-dotnet/openai-dotnet/examples/aspnet-core/Program.cs(41,47): error CS0246: The type or namespace name 'ILogger<>' could not be found (are you missing a using directive or an assembly reference?) [/home/runner/work/openai-dotnet/openai-dotnet/examples/OpenAI.Examples.csproj]

I'll need to pull this down locally and investigate.

@claudiogodoy99
Copy link
Contributor Author

@jsquire I solve the CI issue, the problem is that the OpenAI.Examples.csproj project automatically includes all .cs files in its directory tree, including the ASP.NET Core files in the aspnet-core subdirectory.

To solve it I removed the aspnet-core subdirectory from the OpenAI.Examples.csproj compilation:

<ItemGroup>
    <!-- Exclude the aspnet-core subdirectory from compilation -->
    <Compile Remove="aspnet-core/**" />
    <Content Remove="aspnet-core/**" />
    <None Remove="aspnet-core/**" />
  </ItemGroup>

@jsquire
Copy link
Collaborator

jsquire commented Jul 18, 2025

@jsquire I solve the CI issue, the problem is that the OpenAI.Examples.csproj project automatically includes all .cs files in its directory tree, including the ASP.NET Core files in the aspnet-core subdirectory.

Thanks! You got there before I was able to loop back.

@jsquire jsquire merged commit ec46fd3 into openai:main Jul 18, 2025
1 check passed
@jsquire
Copy link
Collaborator

jsquire commented Jul 18, 2025

Thank you, again, @claudiogodoy99!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants