Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fluent api for microsoft-esque dependency registration #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tofi92
Copy link

@tofi92 tofi92 commented Jan 5, 2025

Hi, I added a small fluent API for the default Microsoft DI container. This should be familiar to any C# developer using the default DI container.

It is 100% backwards compatible, so manual registration still works - this is reflected in the README.

@tofi92 tofi92 requested a review from f1ana as a code owner January 5, 2025 14:08
@f1ana
Copy link
Owner

f1ana commented Jan 6, 2025

Interesting idea! This could make registration a more intuitive.
My only concern is that if a dev wants to use a Scoped lifetime, they would be unable to do so, since this code assumes Transient all the way down.

@tofi92
Copy link
Author

tofi92 commented Jan 8, 2025

As HttpClient is also a transient dependency, I think there is no benefit for the services to be scoped, because the most costly resource, the HttpClient, will be created everytime regardless.

@f1ana
Copy link
Owner

f1ana commented Jan 8, 2025

As HttpClient is also a transient dependency, I think there is no benefit for the services to be scoped, because the most costly resource, the HttpClient, will be created everytime regardless.

The IHttpClientFactory, which generates the HttpClients, is a singleton correct?
Using this source for reference: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Http/src/DependencyInjection/HttpClientFactoryServiceCollectionExtensions.cs#L41

@tofi92
Copy link
Author

tofi92 commented Jan 12, 2025

Ahh I misremembered and thought HttpClient was used :) Anyway I think it won't make a difference.

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.

2 participants