I am new to dependancy injection but found simple injector which seems simple to use yet powerful.
In my project i have the following layers
Dal - consists of repositories that call dbcontext. Each repo has its own interface which inturn implent IRepository
Eg CompanyRepository implements ICompanyRepository
ICompanyRepository implements IRepository
class CompanyRepository : ICompanyRepository
{
public CompanyRepository(IDbContext context)
{
_context = context;
}
}
Models - all my poco objects
Service - business logic that calls Dal to load model objects. Each service has its own interface which esch implement IService. Eg.
CompanyService implements ICompanyService.
ICompanyService implements IService.
class CompanyService : ICompanyService
{
public CompanyService(ICompanyRepository repo)
{
_repo = repo;
}
}
WebApi - mvc web api project. Should call Service layer to load and save models. No reference to Dal.
In WebApi i have added SimpleInjector. And my CompanyCo troller has 1 constructor like so
class CompanyController : ApiController
{
public CompanyController(ICompanyService service)
{
_service = service;
}
}
Now in my application_start code i register ICompanyService to inject CompanyService. Now i get an error saying that CompanyService expects ICompanyRepository to inject. But my webApi project doesnt reference the dal layer.
How can i get this to work? I shouldnt have to reference the dal from the webapi. I am guessing i am going to get same problem with repos as they have IDbContext in constructor.
Thanks in advance