Open
Description
Background and motivation
As an alternative to #101889 this API would be only exposed as a single method taking the delegate as a type arg. This will avoid array allocation and boxing for the args, and also typechecks that the callsite matches the factory.
API Proposal
namespace Microsoft.Extensions.DependencyInjection
{
public static class ActivatorUtilities
{
+ public static T CreateFactoryOf<T>() where T : Delegate;
}
}
API Usage
// IServiceProvider is specially recognized
var f1 = ActivatorUtilities.CreateFactoryOf<Func<IServiceProvider, TArg, TResult>>();
// but it's optional when not using DI
var f2 = ActivatorUtilities.CreateFactoryOf<Func<TArg, TResult>>();
// Just like Lambda<T> you could choose to use a custom delegate type
var f3 = ActivatorUtilities.CreateFactoryOf<CustomDelegate>();
Alternative Designs
No response
Risks
No response