I have a doubt regarding the correct DI pattern to be used in order to build a decoupled application.
My project structure is:
I want to inject a implementation of the UserManager class, and to achieve this I've added the dependency on Startup.cs of my web app using this statement:
services.AddScoped<IUserManager, UserManager>();
For this, I have to add a project reference for BestBurgerManager.Business project and also use its implementation.
Is that correct from the DI point of view? It seems that it won't has a decoupled design doing this way.
The implementation of my UserManager class is:
public class UserManager : IUserManager
{
private readonly IUserManager _userManager;
public UserManager(IUserManager userManager)
{
_userManager = userManager;
}
public void AddUser(User user)
{
// Adds a user.
}
public User GetUser(int userId)
{
return new User(); // Just to test DI.
}
}
Any help to clarify this is appreciated.