I have the following project layout:
MVC UI
|...CustomerController (ICustomerRepository - how do I instantiate this?)
Data Model
|...ICustomerRepository
DAL (Separate Data access layer, references Data Model to get the IxRepositories)
|...CustomerRepository (inherits ICustomerRepository)
What’s the correct way to say ICustomerRepository repository = new CustomerRepository(); when the Controller has no visibility to the DAL project? Or am I doing this completely wrong?
You could use an IoC container to resolve the mapping for you by registering your own controller factory that allows the container to resolve the controllers – the container will resolve the controller type and inject a concrete instance of the interface.
Example using Castle Windsor
in global.asax in your
MvcApplicationclass:WindsorControllerFactoryclass