Skip to content

Added fluent api for microsoft-esque dependency registration - #38

Open
tofi92 wants to merge 1 commit into
f1ana:masterfrom
tofi92:master
Open

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

Conversation

@tofi92

@tofi92 tofi92 commented Jan 5, 2025

Copy link
Copy Markdown

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

f1ana commented Jan 6, 2025

Copy link
Copy Markdown
Owner

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

tofi92 commented Jan 8, 2025

Copy link
Copy Markdown
Author

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

f1ana commented Jan 8, 2025

Copy link
Copy Markdown
Owner

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

tofi92 commented Jan 12, 2025

Copy link
Copy Markdown
Author

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

@f1ana

f1ana commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Still interested in this PR, however I do not want to force a developer consuming this library to use a prescribed lifetime.

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