I'm in the process of doing the analysis of a potentially big web site, and I have a number of questions.
我正在分析一个潜在的大网站,我有很多问题。
The web site is going to be written in ASP.NET MVC 3 with razor view engine. In most examples I find that controllers directly use the underlying database (using domain/repository pattern), so there's no WCF service in between. My first question is: is this architecture suitable for a big site with a lot of traffic? It's always possible to load balance the site, but is this a good approach? Or should I make the site use WCF services that interact with the data?
这个网站将用ASP来写。NET MVC 3和razor视图引擎。在大多数示例中,我发现控制器直接使用底层数据库(使用域/存储库模式),所以中间没有WCF服务。我的第一个问题是:这个架构适合一个流量很大的大网站吗?加载平衡站点总是可能的,但是这是一个好方法吗?还是让站点使用与数据交互的WCF服务?
Question 2: I would like to adopt CQS principles, which means that I want to separate the querying from the commanding part. So this means that the querying part will have a different model (optimized for the views) than the commanding part (optimized to business intend and only containing properties that are needed for completing the command) - but both act on the same database. Do you think this is a good idea?
问题2:我想采用CQS原则,这意味着我想把查询和命令分开。因此,这意味着查询部分将具有与命令部分不同的模型(针对视图进行优化)(针对业务意图进行优化,并且只包含完成命令所需的属性)——但两者都作用于相同的数据库。你认为这是个好主意吗?
Thanks for the advice!
谢谢你的建议!
1 个解决方案
#1
8
-
For scalability, it helps to separate back-end code from front-end code. So if you put UI code in the MVC project and as much processing code as possible in one or more separate WCF and business logic projects, not only will your code be clearer but you will also be able to scale the layers/tiers independently of each other.
对于可伸缩性,它有助于将后端代码与前端代码分开。因此,如果您将UI代码放入MVC项目中,并在一个或多个独立的WCF和业务逻辑项目中尽可能多地处理代码,那么您的代码不仅更加清晰,而且还能够独立地扩展各个层/层。
-
CQRS is great for high-traffic websites. I think CQRS, properly combined with a good base library for DDD, is good even for low-traffic sites because it makes business logic easier to implement. The separation of data into a read-optimized model and a write-optimized model makes sense from an architectural point of view also because it makes changes easier to do (maybe some more work, but it's definitely easier to make changes without breaking something).
CQRS对于高流量的网站非常有用。我认为CQRS,适当地与一个好的DDD基础库结合在一起,即使对于低流量的站点也很好,因为它使业务逻辑更容易实现。从架构的角度来看,将数据分离到一个读优化模型和一个写优化模型是有意义的,因为它使更改更容易完成(可能需要做更多的工作,但在不破坏某些东西的情况下进行更改肯定更容易)。
However, if both act on the same database, I would make sure that the read model consists entirely of Views so that you can modify entities as needed without breaking the Read code. This has the advantage that you'll need to write less code, but your write model will still consist of a full-fledged entity model rather than just an event store.
但是,如果这两个操作都在同一个数据库上,那么我将确保读取模型完全由视图组成,这样您就可以根据需要修改实体,而不需要破坏读取代码。这样做的好处是,您将需要编写更少的代码,但是您的编写模型仍然由一个完整的实体模型组成,而不仅仅是一个事件存储。
EDIT to answer your extra questions:
编辑回答你的额外问题:
What I like to do is use a WCF Data Service for the Read model. This technology (specific to .NET 4.0) builds an OData (= REST + Atom with LINQ support) web service on top of a data model, such as an Entity Framework EDMX.
我喜欢为读取模型使用WCF数据服务。该技术(特定于。net 4.0)在数据模型之上构建一个OData (= REST + Atom和LINQ支持)web服务,例如一个实体框架EDMX。
So, I build a Read model in SQL Server (Views), then build an Entity Framework model from that, then build a WCF Data Service on top of that, in read-only mode. That sounds a lot more complicated than it is, it only takes a few minutes. You don't need to create yet another model, just expose the EDMX as read-only. See also http://msdn.microsoft.com/en-us/library/cc668794.aspx.
因此,我在SQL Server (view)中构建了一个读取模型,然后从中构建一个实体框架模型,然后在其之上以只读模式构建WCF数据服务。听起来要复杂得多,只需要几分钟。您不需要创建另一个模型,只需将EDMX公开为只读。参见http://msdn.microsoft.com/en-us/library/cc668794.aspx。
The Command service is then just a one-way regular WCF service, the Read service is the WCF Data Service, and your MVC application consumes them both.
命令服务只是一个单向的常规WCF服务,读取服务是WCF数据服务,您的MVC应用程序同时使用这两个服务。
#1
8
-
For scalability, it helps to separate back-end code from front-end code. So if you put UI code in the MVC project and as much processing code as possible in one or more separate WCF and business logic projects, not only will your code be clearer but you will also be able to scale the layers/tiers independently of each other.
对于可伸缩性,它有助于将后端代码与前端代码分开。因此,如果您将UI代码放入MVC项目中,并在一个或多个独立的WCF和业务逻辑项目中尽可能多地处理代码,那么您的代码不仅更加清晰,而且还能够独立地扩展各个层/层。
-
CQRS is great for high-traffic websites. I think CQRS, properly combined with a good base library for DDD, is good even for low-traffic sites because it makes business logic easier to implement. The separation of data into a read-optimized model and a write-optimized model makes sense from an architectural point of view also because it makes changes easier to do (maybe some more work, but it's definitely easier to make changes without breaking something).
CQRS对于高流量的网站非常有用。我认为CQRS,适当地与一个好的DDD基础库结合在一起,即使对于低流量的站点也很好,因为它使业务逻辑更容易实现。从架构的角度来看,将数据分离到一个读优化模型和一个写优化模型是有意义的,因为它使更改更容易完成(可能需要做更多的工作,但在不破坏某些东西的情况下进行更改肯定更容易)。
However, if both act on the same database, I would make sure that the read model consists entirely of Views so that you can modify entities as needed without breaking the Read code. This has the advantage that you'll need to write less code, but your write model will still consist of a full-fledged entity model rather than just an event store.
但是,如果这两个操作都在同一个数据库上,那么我将确保读取模型完全由视图组成,这样您就可以根据需要修改实体,而不需要破坏读取代码。这样做的好处是,您将需要编写更少的代码,但是您的编写模型仍然由一个完整的实体模型组成,而不仅仅是一个事件存储。
EDIT to answer your extra questions:
编辑回答你的额外问题:
What I like to do is use a WCF Data Service for the Read model. This technology (specific to .NET 4.0) builds an OData (= REST + Atom with LINQ support) web service on top of a data model, such as an Entity Framework EDMX.
我喜欢为读取模型使用WCF数据服务。该技术(特定于。net 4.0)在数据模型之上构建一个OData (= REST + Atom和LINQ支持)web服务,例如一个实体框架EDMX。
So, I build a Read model in SQL Server (Views), then build an Entity Framework model from that, then build a WCF Data Service on top of that, in read-only mode. That sounds a lot more complicated than it is, it only takes a few minutes. You don't need to create yet another model, just expose the EDMX as read-only. See also http://msdn.microsoft.com/en-us/library/cc668794.aspx.
因此,我在SQL Server (view)中构建了一个读取模型,然后从中构建一个实体框架模型,然后在其之上以只读模式构建WCF数据服务。听起来要复杂得多,只需要几分钟。您不需要创建另一个模型,只需将EDMX公开为只读。参见http://msdn.microsoft.com/en-us/library/cc668794.aspx。
The Command service is then just a one-way regular WCF service, the Read service is the WCF Data Service, and your MVC application consumes them both.
命令服务只是一个单向的常规WCF服务,读取服务是WCF数据服务,您的MVC应用程序同时使用这两个服务。