The separation of your project is very good and contains exactly the layers it should. The problem is that you have a strong coupling between your layers making your code impossible to unit test Examples: Your view model is strongly coupled to a specific implementation of the service: Service = New CustomerService Your service is strongly coupled to a specific implementation of the repository: Repository = New CustomerRepository To improve this code and weaken the coupling you should consider using constructor injection and a DI framework So for example have your service constructor would take a ICustomerRepository argument and assign the private field to it instead of hardcoding a new instance manually. Also have your service implement an interface and do the same constructor injection in your HomeController constructor so that it has access to the service.
The separation of your project is very good and contains exactly the layers it should. The problem is that you have a strong coupling between your layers making your code impossible to unit test. Examples: Your view model is strongly coupled to a specific implementation of the service: _Service = New CustomerService Your service is strongly coupled to a specific implementation of the repository: _Repository = New CustomerRepository To improve this code and weaken the coupling you should consider using constructor injection and a DI framework.So for example have your service constructor would take a ICustomerRepository argument and assign the private field to it instead of hardcoding a new instance manually.
Also have your service implement an interface and do the same constructor injection in your HomeController constructor so that it has access to the service.
Thanks for the reply. Would you please point me in the right direction to learn about DI? – Sam Striano Feb 21 at 7:39 How does the service found out about the repository then?
Wouldn't the model have to tell it? Would that be breaking the rules? – Sam Striano Feb 21 at 7:43 1 @Sam Striano, the whole point of Inversion of Control is that the service shouldn't find out about the specific repository.
This repository should be injected by the consumer of the service (i.e. The controller), then the same principle applies about the controller because it shouldn't know about the service, it should be injected, etc, etc ... To find more about IOC you may first read the original article written by Martin Fowler. – Darin Dimitrov Feb 21 at 7:52 1 For applying DI in ASP.NET MVC 3 you have two possibilities: either register a custom controller factory (which worked also in previous versions) or use the new IDependencyResolver.
– Darin Dimitrov Feb 21 at 7:53.
The separation of your project is very good and contains exactly the layers it should. The problem is that you have a strong coupling between your layers making your code impossible to unit test.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.