views:

709

answers:

1

Dear All!

I try to set-up a clean and flexbible application-framework for data-centric applications with silverlight-only UI. I want to have a strict seperation of concerns, and want to be as flexible as possible (e.g. exchange the ORM later) while still reducing the amount of code.

It took me weeks to figure out an appropriate architecture, and although my latest approach seems to fit my requirements I'm still not completely convinced, that this way will be the best and is technically possible.

Here is how my solutions-explorer looks like:

  • MyCompany.MyApplication.Entities
    Class library - project, which contains only the domain (business) objects, such as Customers, Adresses, etc. These are POCOs with the [Serializable] - attribute, but do not any other code. All properties are marked as virtual, so that classes could derive and overwrite the properties.

  • MyCompany.MyApplication.DataAccess
    Class library - project, which contains the nHibernate - specific code (Sessions) to load, save and delete the domain objects. This project has references to the Entities-project and also to the nHibernate-libraries.

  • MyCompany.MyApplication.Core
    Class library - project, which contains the business logic, and often just maps the methods form the DataAccess - project, such as GetAllCustomers, SaveCustomer, etc. It has references to the Entities-project and the DataAccess-project.

  • MyCompany.MyApplication.Web
    Web-application - project, which hosts the silverlight-client-app and also the WCF-services to communicate with the client-side. To expose the domain-objects to the client-side, these classes are derived and all the properties are overwritten and marked with the [DataMember] - attribute. It has references to the Entities-projects and the Core-projects.

  • MyCompandy.MyApplication.Silverlight
    Sivlerlight 3.0 - project, which represents the userinterface. It has only service-references to the WCF-Services exposed by the Web-project. The actual domain-objects aren't accesssible, but the auto-generated proxy-classed replace them.

Please tell me, what do you think about this architecture, and if there are any conflicts! Further question: Is there any way, to avoid the properties of the domain-objects being virtual and the need to overwrite them in order to make them accessible trough WCF?

Best regards, Daniel Lang

+1  A: 

Daniel, you are not going to get around the nhiberante requirement of virtual properties. Have you thought about using Dto's?

Nathan Fisher
I actually don't get, how I could benefit from using DataTransferObjects? As far as I know, they "just" encapsulate my BusinessObjects... ?
dlang
The benifit comes from when you need to modify your business objects, especially when you add or remove properties. Your web service contract will change when you change your Entity/Business/Domain Object, thus breaking your web app. Having a DTO allows you to change your Entities while allowing applications that depends on the webservice to sill function without change.
Nathan Fisher
have a look at these questionshttp://stackoverflow.com/questions/1688473/dtos-vs-serializing-persisted-entitieshttp://stackoverflow.com/questions/1190718/how-do-i-serialize-all-properties-of-an-nhibernate-mapped-objecthttp://stackoverflow.com/questions/1958684/nhibernate-how-do-i-xmlserialize-an-isettHope these help
Nathan Fisher
Thank you!After reading the articles I'm pretty scared why I haven't already heard from the advantages of DTOs before! Great!
dlang