ASP.NET MVC应用程序架构“指南”

时间:2021-11-24 03:24:49

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

我正在寻找一些基于ASP.NET MVC的CMS应用程序架构的反馈。

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

域模型 - 除了System类之外什么都不依赖于定义类型。目前,大多贫血。

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

ViewModelMapper - 在视图模型和域模型之间来回转换的服务

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

我的域模型主要用作数据传输(DTO)对象,目前逻辑很少。我发现这很好,因为它取决于什么(甚至不是服务层中的类)。

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.

服务层有点棘手......我只希望控制器能够访问视图模型以便于GUI编程。但是,有些服务需要相互通信。例如,我有一个事件服务,在标记内容,创建博客帖子等时通知其他侦听器服务。目前,将域模型作为输入或返回它们的方法标记为内部,因此它们不能被控制器。

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!

1 个解决方案

#1


2  

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

    验证 - 具有两步验证 - 步骤1:域级别类强制执行其自身的有效性(通过属性或任何其他机制)。步骤2:存储库确保对象在存储库的上下文中有效

  • 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

    依赖注入 - 使用DI框架注入依赖项。它对单元测试很有用。此外,如果需要跨服务调用的服务层,请检查有关聚合服务的这篇文章是否有用:http://blog.ploeh.dk/2010/02/02/RefactoringToAggregateServices.aspx

    • ViewModels - might be tempting to re-use, but wait & watch before you finally decide
    • ViewModels - 可能很容易重复使用,但在你最终决定之前等待观察

HTH.

#1


2  

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

    验证 - 具有两步验证 - 步骤1:域级别类强制执行其自身的有效性(通过属性或任何其他机制)。步骤2:存储库确保对象在存储库的上下文中有效

  • 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

    依赖注入 - 使用DI框架注入依赖项。它对单元测试很有用。此外,如果需要跨服务调用的服务层,请检查有关聚合服务的这篇文章是否有用:http://blog.ploeh.dk/2010/02/02/RefactoringToAggregateServices.aspx

    • ViewModels - might be tempting to re-use, but wait & watch before you finally decide
    • ViewModels - 可能很容易重复使用,但在你最终决定之前等待观察

HTH.