Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC application architecture "guidelines"

I'm looking for some feedback on my ASP.NET MVC based CMS application architecture.

Domain Model - depends on nothing but the System classes to define types. For now, mostly anemic.

Repository Layer - abstracted data access, only called by the services layer

Services Layer - performs business logic on domain models. Exposes view models to the controllers.

ViewModelMapper - service that translates back and forth between view models and domain models

Controllers - super thin "traffic cop" style functionality that interacts with the service layer and only talks in terms of view models, never domain models

My domain model is mostly used as data transfer (DTO) objects and has minimal logic at the moment. I'm finding this is nice because it depends on nothing (not even classes in the services layer).

The services layer is a bit tricky... I only want the controllers to have access to viewmodels for ease of GUI programming. However, some of the services need to talk to each other. For example, I have an eventing service that notifies other listener services when content is tagged, when blog posts are created, etc. Currently, the methods that take domain models as inputs or return them are marked internal so they can't be used by the controllers.

Sounds like overkill? Not enough abstraction? I'm mainly doing this as a learning exercise in being strict about architecture, not for an actual product, so please no feedback along the lines of "right depends on what you want to do".

thanks!

like image 734
Jason Barile Avatar asked Nov 05 '22 14:11

Jason Barile


1 Answers

Overall, the design looks good to me.

There are a few more items I might do:

  • Validations - have a 2 step validation -
    Step 1 : the domain-level classes enforce their own validity (via attributes or any other mechanism).
    Step 2: The repository ensures that the object is valid in the context of the repository

  • Dependency Injection - use a DI framework to inject dependencies. It will be useful for unit testing. Also, If the service layer where you need to call across services, check if this article on Aggregate Service is useful: http://blog.ploeh.dk/2010/02/02/RefactoringToAggregateServices.aspx

    • ViewModels - might be tempting to re-use, but wait & watch before you finally decide

HTH.

like image 191
Sunny Avatar answered Nov 11 '22 15:11

Sunny