Reputation: 2623
I working on a Saas application that will be using ASP.NET MVC 4 & SQL Server. I am planning to have a data layer (using EF5), a service layer (possible only have RESTful services), a DTO layer, and Web UI layer. Later on, I am planning to extend this application to mobile platform, for both Android & iPhone ... maybe windows tablet.
Usually, one would create a separate layer for domain objects where business rules are contained. However, in my case, if I did that, then I would have to replicate the rules again for android ... and yet again for iphone. So, I was thinking to have the business rules within the service layer itself. However, for whatever reason that doesn't feel right.
Any suggestions on this?
Upvotes: 0
Views: 563
Reputation: 1971
From a performance perspective, duplicating the rules for each platform is the way to go (because it separates the processing between different devices) however from a maintenance, consistency, etc. perspective you should place the business rules in a workflow that is within / parallel to the service layer.
http://msdn.microsoft.com/en-us/library/ee658103.aspx
Upvotes: 0
Reputation: 101150
You said that you have a service layer. The business logic should be behind it.
Business layer -> (shared business objects) -> service layer -> (shared DTOs) -> presentation layers
Where the presentation layers are MVC4, Android, IPhone etc. They can all share the same DTOs but serialized differently.
Upvotes: 1
Reputation: 2954
The presentation layer must be what it is.. just a presentation layer. Your business rules should not be there. I understand that your DTO's will be the objects that will feed your clients (android, iphone, web,etc..), so there's no need to transfer your business objects to the UI. Keep your business layer isolated in the server side and make your clients work with it just to get the data they need to show.
My suggestion is to make the presentation layer agnostic of the business rules. Using this approach will make your solution scalable and easy to extend. Is a good way to apply separation of concerns.
Saying that.. You might be worried about how to share your DTO's across different platforms. I think the best approach would be to not feed your presentation layer with .NET objects since you are planning to use different programming languages and technologies in your presentation layer. JSON and REST could play very well for your problem. I suggest to use Asp.net Web Api to work with json objects. Objective-c, Java and Javascript (for your Web UI) can work with this kind of objects.
Upvotes: 2