Scrutor icon indicating copy to clipboard operation
Scrutor copied to clipboard

Add Keyed Service name support

Open jcambert opened this issue 6 months ago • 1 comments

@khellang Add ServiceKeyAttribute to keyed services. ServiceDescriptor make the rest in LifetimeSelector.Populate

jcambert avatar Jul 07 '25 12:07 jcambert

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.

dgioulakis avatar Jul 07 '25 22:07 dgioulakis