Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension method for adding the implementation and interface of a service #45

Open
carmeleve opened this issue Jun 11, 2020 · 1 comment

Comments

@carmeleve
Copy link

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
Copy link
Contributor

mwadams commented Jun 11, 2020

(Something like that- it was code written in a github comment which is rarely exemplary :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants