How can I inject one class into another inside a .NET Core library project?
Where should I configure DI as it is done in StartUp Class ConfigureServices in API project?
Asp.net-core – Dependency Injection in .NET Core inside a class library
.net coreasp.net-coreclass-librarydependency-injection
Related Topic
- Inversion of Control vs Dependency Injection
- Why does one use dependency injection
- R – Confused on const correctness with static array of pointers to const objects
- Asp.net-core – Using Dependency Injection with .NET Core Class Library (.NET Standard)
- C# – .net Core Quartz Dependency Injection
- .net – the difference between .NET Core and .NET Standard Class Library project types
- .NET Standard vs .NET Core
- C# – Using ‘UseMvc’ to configure MVC is not supported while using Endpoint Routing
Best Answer
After googling a lot I could not find a comprehensive answer with an example to this question. Here is what should be done to use DI in Class library.
In your library:
Then extend IServiceCollection in the library:
Lastly in the main app StartUp (API, Console, etc):