简单的应用程序架构的建议 [英] Simple application architecture advice

查看:116
本文介绍了简单的应用程序架构的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个松散耦合,高度可测试一个小型的演示Web应用程序,有漂亮干净的code,等等,总之,我与做事的正确方法试验。 ;)

I'm attempting to create a small demo web application that is loosely coupled, highly testable, has nice clean code, etc. In short, I'm experimenting with doing things the right way. ;)

我目前有三个项目在我的莫扎特的解决方案:

I currently have three projects in my Wolfie solution:


  • Wolfie.Core - 包含商业实体

  • Wolfie.Data - 包含数据访问code,引用核心

  • Wolfie.Web - 将是南希的网站

由于它代表的核心一无所知其他任何项目。数据引用核心为核心的数据将返回类型。所以在这一点上,我发现自己意识到,网络将需要引用核心和数据,以便能够作为工作的实体类型是核心和数据库调用数据。

As it stands the Core knows nothing about any of the other projects. Data has to reference Core as Core has the types that Data will return. So at this point I find myself realising that Web will need to reference both Core and Data to be able to work as the entity type is in Core and the database calls are in Data.

所有的数据存储库类都有接口,以便存储库可用于测试被嘲笑了。

All of the repository classes in Data have interfaces so that the repositories can be mocked out for testing.

我不认为我想提出任何具体的数据库code或引用为核心,我想保持我的实体业务规则出数据的。

I don't think I want to put any database specific code or references into Core, and I want to keep my entity business rules out of Data.

是不是的正确的从Web引用这两个项目?或将所需的Web和其他人之间的另一个项目,使网站只引用一个地方,不那么负责调用数据的方法等。

Is it correct to reference both projects from Web? or would another project between Web and the others be required so that Web only references the one place and isn't then responsible for calling Data methods etc.

什么我的目标是一个架构在我的核心应用是独立于数据和Web层的都有。

What I'm aiming for is an architecture where my core application is independent of both the Data and Web layers.

我希望我做的部分的感觉,我期待着一些有用的回复。

I hope I've made some sense and I look forward to some helpful replies.

推荐答案

我想你争取一个合理的目标,这将创造一个坚实的应用程序架构。我曾亲自制定上采用了类似的架构,您所描述一个企业Web应用程序,和它的工作非常好该应用程序。

I think you are striving for a reasonable goal which will create a solid application architecture. I have personally worked on an enterprise web application that used a similar architecture to the one you are describing, and it worked very well for that application.

在该应用程序,您所访问的业务逻辑在其自己的域组件(你的核心组装)分离和引用的.NET框架之外什么都没有。为了连接到外部业务组件,如数据库和其他Web服务,出现了基础设施组件(你的数据组装)。该应用程序的关键是,在基础设施组件,每个实现在域装配了接口,并返回域装配的对象(就像你描述的)。这一点,当然,必要从基础设施的引用域

In that application, the domain business logic was isolated in its own "Domain" assembly (your "Core" assembly) and referenced nothing outside of the .NET framework. In order to connect to external business components, such as the database and other web services, there was an "Infrastructure" assembly (your "Data" assembly). The key for that application is that each implementation in the Infrastructure assembly was interfaced in the Domain assembly, and returned Domain assembly objects (just as you describe). This, of course, necessitated a reference from Infrastructure to Domain.

要配合到一起,一个Web应用程序组件(你的网组装)引用两个域和基础设施组件和使用IoC容器来解决所有的应用程序依赖。当请求进来的Web应用程序,它可以解决相应的域的合同来服务这将启动IoC解决方案调用链的要求。注册基础设施实现之外,Web应用程序组件不关心基础设施组件存在。

To tie it all together, a "WebApp" assembly (your "Web" assembly) referenced both the Domain and Infrastructure assemblies and used an IoC container to resolve all of the application dependencies. When requests came in to the WebApp, it would resolve the appropriate "Domain" contract to serve the request which would start the IoC resolution call chain. Outside of registering the Infrastructure implementations, the WebApp assembly does not care that the Infrastructure assembly exists.

这工作这么好该应用程序的原因是,它实现了你在你的问题中所述的目标:

The reason this worked so well for that application is that it achieved the goals you stated in your question:


  • 有在商业领域没有外部的引用。

  • 业务领域的应用是完全独立于web前端和后端数据库的都有。

这借的可测性的大量的到你的业务领域,以及一个的很多的灵活性,如何前端接口与您的域名。事实上,这种灵活性的的是什么使得它如此测试。这种灵活性有其他好处。例如,与孤立的业务领域,你可以很容易地code了一个新的CLI或WPF前端的挂钩到一个文件系统后端没有,如果你想不断变化的业务领域code的废料部署和本地的机器上运行客户端。

This lends a lot of testability to your business domain, and a lot of flexibility to how front-ends interface with your domain. In fact, that flexibility is what makes it so testable. That flexibility has other benefits as well. For instance, with your business domain that isolated, you could easily code up a new CLI or WPF front-end that hooked into a file-system back-end without changing a scrap of business domain code if you wanted to deploy and run your client locally on a machine.

虽然这个例子会略显牵强,在我上面所引用的申请的情况下,开发团队正在考虑建立一个Web服务前端,以补充现有的MVC网站的前端。这只是对于球队现实的可能性,因为他们安装该应用程序像你描述的。

Though that example may seem slightly far-fetched, in the case of the application I was referencing above, the development team is contemplating building a Web Services front-end to complement the already existing MVC website front-end. This is only a realistic possibility for that team because they setup that application like you are describing.

这篇关于简单的应用程序架构的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆