Using asp.net 5
I\'d like my controller to be injected with a Func
instead of T
For example:
I wrote a little extension method that registres the service and the factory (Func
):
public static class IServiceCollectionExtension
{
public static IServiceCollection AddFactory(this IServiceCollection serviceCollection)
where TService : class
where TServiceImplementation : class, TService
{
return serviceCollection
.AddTransient();
.AddSingleton>(sp => sp.GetRequiredService);
}
}
Usage:
serviceCollection
.AddFactory()