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?
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.