Extension method for adding the implementation and interface of a service
carmeleve opened this issue · 1 comments
carmeleve commented
public static IServiceCollection AddSingletonWithInterface<TInterface,TImplementation>(this IServiceCollection services)
where TImplementation : TInterface
{
services.AddSingleton<TImplementation>();
services.AddSingleton<TInterface, TImplementation>(s => s.GetRequiredService<TImplementation>());
return services;
}
mwadams commented
(Something like that- it was code written in a github comment which is rarely exemplary :) )