I want to add some services in my class library project and I found some ways on Google for this https://mcguirev10.com/2018/01/31/net-core-class-library-dependency-injection.html. However, I don't want to register services in my console app or web app. I want to create a complete solution in the class library, where the user doesn't need to register the service when using the library.
Here is what I have tried:
This is my service class:
public static class ServiceCollectionExtension
{
public static IServiceCollection AddServices(this IServiceCollection services)
{
services.AddSingleton<IClient, Client>();
return services;
}
}
and I found the register method on the Internet like this:
public class Program
{
public static async Task Main(string[] args)
{
var services = new ServiceCollection();
services.AddUsefulService();
}
}
but I don't want to do it like that.