I have gone through the link:
https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/dependency-injection
and learnt that how I can use dependency injection for Web API.
As mentioned in the above link I can use Startup (Startup.cs) class for dependency injection inside API layer. But how can achieve dependency injection for the .NET Core Class Library. Below is the screenshot how I am adding a class library.
And my project structure is
In the project “DataManagement.Repository” I have written a class “UserRepository” and in the project “DataManagement.Repository.Interfaces” written an Interface “IUserRepository”.
In the project “DataManagement.Business” I have written a class “UserManager”
class UserManager
{
private IUserManager _userManager;
public UserManager(IUserManager userManager)
{
_userManager = userManager;
}
}
As you can see that I am trying to achieve dependency injection through the constructor.
But I am not sure that what changes need to be done for enabling dependency injection inside .NET Core Class Library (.NET Standard).