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)
-
0
please help me !
-
0
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>
-
0
thanks....
how can call the class (the class constructure need 1 argument) public class PersonAppService : IPersonAppService { private readonly IRepository<Person> _personRepository;
public PersonAppService(IRepository<Person> personRepository) { _personRepository = personRepository; } public void CreatePerson(CreatePersonInput input) { person = new Person { Name = input.Name, EmailAddress = input.EmailAddress }; _personRepository.Insert(person); }
}
-
0
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>