Ok, I'm trying to rewrite huge part of code in this ASP.NET MVC application that was poorly designed. I've read a lot about many concepts and patterns some of them were little more advanced but I found myself to be confused about very basic staff.
So what should be overall structure of MVC application ?
I have something that wraps data access - lets call it "data layer". It might be implementation of Repository pattern or just some Entity framework context class or...
Then I'll have services layer wrapping business logic.
What should scenario of serving http request ? Controller gets created for the request --> action on it is executed. And then ? I create instance of "data layer" and pass it to the methods service layer commit changes and display results ?
So each method in all services (belonging to service layer) should take some "data layer" class as parameter so it can talk to "data layer" ? Or do I pass "data layer" reference to services in constructor ? In that case I have to create new service for each request right ?
I've read about using using
keyword in controller to pass "data layer" reference to services. The other approach is using dependency injection. I don't really understand the difference... And why not just create it in controllers constructor and keep it simple ?