Skip to content

Instantly share code, notes, and snippets.

@jrob5756
Created Sep 29, 2018
Embed
What would you like to do?
public static class ServiceCollectionExtensions
{
public static void AddFactory<TService, TImplementation>(this IServiceCollection services)
where TService : class
where TImplementation : class, TService
{
services.AddTransient<TService, TImplementation>();
services.AddSingleton<Func<TService>>(x => () => x.GetService<TService>());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment