Reputation: 319
I want to create a class library project, and in that project include some interfaces and classes that implements those interfaces.
After that, I want to provide this class library project, as a nuget package, so, will be ideal having some kind of extension from IServiceCollection, in order to after the nuget installation, with one line of code in the Startup.cs
, ConfigureServices()
on the application that is using the nuget, make something like that:
services.AddServicesFromMyNugetPackage()
and that method will be execute, based on IServiceCollection
methods, my configuration for DI.
any idea?
Upvotes: 4
Views: 10997
Reputation: 411
In your library, you can create a static class and write some extensions methods where you can register your dependencies as the following example:
public static class ServicesExtensions
{
public static void AddMyLibraryServices(this IServiceCollection services)
{
// register your services here
}
}
and then in your startup file:
services.AddMyLibraryServices();
Upvotes: 16