-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-DependencyInjectionfeature-request
Milestone
Description
AB#1244416
Currently Scrutor has these:
I think we should consider adding something similar in the box for a couple of reasons:
- It helps when default implementations are internal or non virtual.
- It promotes composition over inheritance
This needs to be built in a way that doesn't require container authors to change anything (that's why extension methods are being proposed).
cc @khellang Since he may want to contribute this 😉.
Some things I am concerned about in the above implementation:
- Performance of those methods, some of them allocate (https://github.com/khellang/Scrutor/blob/338a59333c7eafe25d5aefdd22434653c83eb9ab/src/Scrutor/ServiceCollectionExtensions.Decoration.cs#L249)
- Performance of Scanning the IServiceCollection, multiple times (https://github.com/khellang/Scrutor/blob/338a59333c7eafe25d5aefdd22434653c83eb9ab/src/Scrutor/ServiceCollectionExtensions.Decoration.cs#L294)
- Performance of service resolution https://github.com/khellang/Scrutor/blob/338a59333c7eafe25d5aefdd22434653c83eb9ab/src/Scrutor/ServiceCollectionExtensions.Decoration.cs#L333-L356,
ActivatorUtilities.GetServiceOrCreateInstanceshould be swapped withCreateFactory. - The quirks around the fact that this mutates the service collection in place (https://github.com/khellang/Scrutor/blob/338a59333c7eafe25d5aefdd22434653c83eb9ab/src/Scrutor/ServiceCollectionExtensions.Decoration.cs#L296). It affects code like this:
WorksDoes not workservices.AddSingleton<IFoo, Foo>(); services.Decorate<IFoo, Foo2>();
services.Decorate<IFoo, Foo2>(); services.AddSingleton<IFoo, Foo>();
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-DependencyInjectionfeature-request