I am using asp.net boilerplate to create new project.
I have defined new service as follows:
public class Employee : Entity<int>
{
public string FName { get; set; }
public string LName { get; set; }
}
public interface IEmployeeAppService : IApplicationService
{
Employee AddEmployee(Employee emp);
List<Employee> GetAll();
}
public class EmployeeAppService : MyTestProjectAppServiceBase, IEmployeeAppService
{
private IRepository<Employee, int> _employeeRepository;
public EmployeeAppService(IRepository<Employee, int> repo)
{
_employeeRepository = repo;
}
public Employee AddEmployee(Employee emp)
{
return _employeeRepository.Insert(emp);
}
public List<Employee> GetAll()
{
return _employeeRepository.GetAllList();
}
}
I want to use the service in HomeController:
public class HomeController : MyTestProjectControllerBase
{
IEmployeeAppService service;
public HomeController(IEmployeeAppService svc)
{
service = svc;
}
}
When I run the application I get following error:
Can't create component 'MyTestProject.Services.EmployeeAppService' as it has dependencies to be satisfied.
'MyTestProject.Services.EmployeeAppService' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`2[[MyTestProject.Domain.Employee, MyTestProject.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' which was not registered.
How do I register the EmployeeAppService
dependency with HomeController
?
UPDATE
I tried the following code
IocManager.Register(typeof(IRepository<Employee, int>),
typeof(EmployeeAppService),
Abp.Dependency.DependencyLifeStyle.Transient);
but then it displays this error
There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.
This normally happens when your Entity (Employee in this case) is not specified in you DbContext.
Just add the following property to your DbContext class and you should be good to go:
public virtual IDbSet<Employee> Employees { get; set; }