Scrutor
Scrutor copied to clipboard
Add Keyed Service name support
@khellang Add ServiceKeyAttribute to keyed services. ServiceDescriptor make the rest in LifetimeSelector.Populate
This is very much needed behavior. Hope this can get fast-tracked into the next release.
Although, in the future it might be nice to have a solution that doesn't require our services to be decorated with DI-specific metadata.
e.g.
services.Scan(
selector => selector
.FromAssemblyOf<Program>()
.AddClasses(filter =>
filter.AssignableTo<View>()
.WithAttribute<AzureResourceTypeAttribute>(),
false
)
.AsKeyed<View>(implementationType => implementationType.GetCustomAttribute<AzureResourceTypeAttribute>()!.ResourceTypeNamespace)
.WithTransientLifetime()
);
I'd like to be able to write a Func<Type, string> that serves as a key selector.