Skip to content

Added fluent api for microsoft-esque dependency registration#38

Open
tofi92 wants to merge 1 commit intof1ana:masterfrom
tofi92:master
Open

Added fluent api for microsoft-esque dependency registration#38
tofi92 wants to merge 1 commit intof1ana:masterfrom
tofi92:master

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