简体   繁体   中英

3-Tier Architecture with multiples presentation layer

I'm trying to build a new application and running into troubles to make it clean.

The idea was to make it that way:

  • WebSite1 (Presentation Layer)
    • XAML pages
    • Code behind pages
    • What we call PageViewModel (Object that represents page model)
  • WebSite2 (Presentation Layer)
    • Same as website1
  • WebSiteX (Presentation Layer)

    • Same as website 1
  • Business project

    • Services (Will be call by code behind pages, transform DAL Object into ViewModel readable by website)
    • ViewModel (Represents real object can be use in several pages/websites)
  • DAL project

    • Manager (Call by services, return DAL object)
    • DAL (Access to database or other sources)

My ViewModels are stored into a seperated project and can be used in various websites if needed.

I feel dirty about the fact that the presentations rules (like this should be a number or this is required) will be stored into the business layer (attributes inside the ViewModels). It's also possible that two websites uses the same object but with different presentations rules (required in one case not in the other).

The only other way I see is to put the Services and the ViewModels inside each websites but if they use similar objects the code will be duplicated.

How would you do ?

Thanks for reading.

I think presentations rules can be in PageViewModel or you can have validation rules when transforming from PageViewModel to BusinessObjects (you are calling them View Models).

Also, what you have already mentioned would also work

The only other way I see is to put the Services and the ViewModels inside each websites but if they use similar objects the code will be duplicated.

I would keep duplicate ViewModels and not Services. Yes, the code is duplicate, but this gives me freedom and will be purposeful for having separate websites maintained separately despite of having same underlying Business model.

I think this might be a good instance for inheritance. Create a base instance of your PageVM classes, and override behavior in the different sites.

Try to separate things like "requiredness" into separate methods that can be overridden, possibly declaring it as abstract in the base instance so that it forces you to define that logic in the implementing version.

The trickier bits will be the construction of the PageVM objects, and for that you probably want to investigate Factory or Builder patterns to have your UI projects create the custom PageVM objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM