Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

proplem in IRepository #1778


User avatar
0
mohammedthamer created

hello how are you this code to insert

public class rep_user1:IUserApp
    {
        private  IRepository<user_information> _userRepository;

  
        public void Createuser(loginModel input)
        {
            //   input = new user_information { Name = input.name, EmailAddress = input.EmailAddress };
            var userval = new user_information();
            userval.name = input.UserName;
            userval.password = input.Password;
            _userRepository.Insert(userval); //proplem here  Object reference not set to an instance of an object.
        }
    }

and here add new account

loginModel us = new loginModel();
            us.UserName = "moh";
            us.Password = "1994";
    rep_user1 rp = new rep_user1();
           rp.Createuser(us);

proplem in IRepository.insert show Object reference not set to an instance of an object.

Regards......


4 Answer(s)
  • User Avatar
    0
    mohammedthamer created

    please help me !

  • User Avatar
    0
    hikalkan created
    Support Team

    This seems a simple C# error. Are you injecting user repository into your constructor? See DI document: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection#DocResolveConstAndProp">http://www.aspnetboilerplate.com/Pages/ ... nstAndProp</a>

  • User Avatar
    0
    mohammedthamer created

    thanks....

    how can call the class (the class constructure need 1 argument) public class PersonAppService : IPersonAppService { private readonly IRepository<Person> _personRepository;

    public PersonAppService(IRepository&lt;Person&gt; personRepository)
    {
        _personRepository = personRepository;
    }
    
    public void CreatePerson(CreatePersonInput input)
    {        
        person = new Person { Name = input.Name, EmailAddress = input.EmailAddress };
        _personRepository.Insert(person);
    }
    

    }

  • User Avatar
    0
    hikalkan created
    Support Team

    You will not create the class directly. You will use dependency injection. If you are new, I suggest you to start from this document: <a class="postlink" href="http://www.codeproject.com/Articles/791740/Using-AngularJs-ASP-NET-MVC-Web-API-and-EntityFram">http://www.codeproject.com/Articles/791 ... EntityFram</a>