I am writing a web application using MVC and Entity Framework. My current structure includes Service layer, Business Layer (Domain Model), Data Layer, Presentation Layer and Mapper. Flow is like this. Presentation Layer makes request to Service Layer like service.GetSomeData()
. Service layer forward it to Data layer and data layer maps the object to entity using mapper layer and return a DTO back to service layer which sends it back to presentation layer. Service layer implements Facade pattern and Data Layer is DTO pattern. Things are good so far.
Now Serious Problem Came Up: My controllers are getting fatter and fatter by doing additional work which should be in business layer and data layer has also started doing business logic stuff. In short i am all over the places. By business logic stuff in data layer i mean if my DTO object needs some additional information to load or need to make some decision for some behavior it does all weird and stupid if checks and adds it to the object after the data is retrieved from table with in data layer. It has also start doing bunch of 'IF this then this IF that then that things' which in my thoughts should not happen at data layer. I have started working in design patterns and really wanted to make it better, but i think i have failed at this point. So i decided i should move my business logic from controller and data layer to business layer. However, I am not able to figure out how i can do this? I mean, suppose my one controller is making 10 calls to database using data layer and getting data and what not. Do i have to create same 10 methods in business layer and make a call to data layer from business layer, get the object back from data layer, perform the business logic and send it back to presentation layer Or I should do something with Service Layer that does this business logic processing before passing the DTO back to presentation layer?
I have completely hit the wall and it's not letting me sleep either :(.
I will really appreciate if somebody just guide me towards the right path
Aucun commentaire:
Enregistrer un commentaire