From d8ac6f1d27a75f5f1261fb9b58954be8f49de8fd Mon Sep 17 00:00:00 2001 From: vby Date: Wed, 25 Dec 2024 23:24:36 +0100 Subject: [PATCH] Added keyed services support --- .../ServiceCollectionExtensions.Decoration.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Scrutor/ServiceCollectionExtensions.Decoration.cs b/src/Scrutor/ServiceCollectionExtensions.Decoration.cs index 189ffad7..3905d606 100644 --- a/src/Scrutor/ServiceCollectionExtensions.Decoration.cs +++ b/src/Scrutor/ServiceCollectionExtensions.Decoration.cs @@ -25,6 +25,23 @@ public static IServiceCollection Decorate(this IServiceCol return services.Decorate(typeof(TService), typeof(TDecorator)); } + /// + /// Decorates all registered services of type + /// using the specified type . + /// + /// The services to add to. + /// The of the service. + /// If no service of the type has been registered. + /// If the argument is null. + public static IServiceCollection DecorateKeyed(this IServiceCollection services, string serviceKey) + where TDecorator : TService + { + Preconditions.NotNull(services, nameof(services)); + Preconditions.NotNull(serviceKey, nameof(serviceKey)); + + return services.Decorate(DecorationStrategy.WithType(typeof(TService), serviceKey, typeof(TDecorator))); + } + /// /// Decorates all registered services of type /// using the specified type .