-
-
Notifications
You must be signed in to change notification settings - Fork 266
Open
Description
Actually, when I want to decorate specified service by key string, there is no way to do that, but I noticed DecorationStrategy.WithType
method can create DecorationStrategy
and i can decorate by key through method Decorate
by overload. But I can only do that by reflection. Please consider making WithType
to public accessibility
public static IServiceCollection DecorateKeyedService<TService, TDecorator>(
this IServiceCollection services,
string key
)
{
var method = typeof(DecorationStrategy).GetMethod(
"WithType",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic
);
if (method == null)
{
throw new InvalidOperationException("DecorationStrategy.WithType method not found");
}
var obj =
method?.Invoke(
null,
[typeof(TService), key, typeof(TDecorator)]
) as DecorationStrategy;
if (obj == null)
{
throw new InvalidOperationException("DecorationStrategy.WithType invocation failed");
}
services.Decorate(obj);
return services;
}
Metadata
Metadata
Assignees
Labels
No labels