'How to force passing parameter to the constructor using dependency injection

To ensure proper data initialization and ensure data sanitation, we used immutable objects. To ensure that they were initialized, we passed them through the constructor.

UserManager userManager = new UserManager(obj);

class UserManager
{
   object _obj;

    public UserManager(object o)
    {
        _obj = o;
    }
}

In UserManager class we have one constructor. So it forces us to pass the name parameter whenever we create the instance of the class UserManager.

Now we started using dependency injection and we are passing UserManager as a dependency, in this way are not able to force to pass name parameter.

Is there any way we can do that. We are trying to implement the same in ASP.NET Core.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source