'How to pass model as a Parameter in Repository method at controller?

So my problem is like that, When I am trying to pass the model in repository method on controller I getting error like this Object reference not set to an instance of an object.

Please help me to solve my issue. Thankyou

Please click on the image right below for your refer. Please Refer this picture to understand my problem.

 public UserController()
    {
    }

    public IUser _userObj;

    public UserController(IUser userObj)
    {
        _userObj = userObj;
    }

 [HttpPost]
    public async Task<ActionResult> AddUser(UserModel model)
    {
        bool isError = true;
        var message = string.Empty;
        try
        {
            if (ModelState.IsValid)
            {
                var res = await _userObj.AddUser(model);
                isError = false;
                if (res > 0)
                {
                    message = "Sucess";
                    isError = false;
                }
            }
            return Json(new 
            {
                IsError = isError,
                Message = message
            }, JsonRequestBehavior.AllowGet);
        }
        catch (Exception e)
        {
            return Json(new
            {
                IsError = isError
            }, JsonRequestBehavior.AllowGet);
        }
    }


Solution 1:[1]

If you are using IoC container like Autofac, register your controller and set your dependency resolver. Check this link https://autofaccn.readthedocs.io/en/latest/integration/mvc.html#quick-start.

Solution 2:[2]

You need to add dependency injection for your Interface in Startup.cs file.

In Startup.cs file inside ConfigureService method add

services.AddScoped<IUser, User>();

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 ian
Solution 2 Sagar Malde