架构:The Onion Architecture : part 2(洋葱架构:第二篇)(转载)
原位地址:http://jeffreypalermo.com/blog/the-onion-architecture-part-2/。
In part 1, I introduced an architectural pattern that I have named "Onion Architecture". The object-oriented design concepts are not new, but I'm pulling together a lot of techniques and conventions into a single pattern and giving it a name. My hope is that the industry can use this name to communicate the architectural approach where appropriate.
Part 2: Practical example:
CodeCampServer uses the Onion Architecture. If you are looking for a full, working application as an example, please have a look. The practical example I put before you is taken directly from CodeCampServer. It is a narrow, vertical slice of an example. I'm keeping the scope small as to be digestible. I'll start with a diagram so you can understand where all the code resides within the layers of the onion.
CodeCampServer uses the ASP.NET MVC Framework, so SpeakerController is part of the user interface. This controller is coupled to the ASP.NET MVC Framework, and there is no getting around that. SpeakerController depends on IConferenceRepository and IUserSession (and IClock, but we'll omit that). The controller only depends on interfaces, which are defined in the application core. Remember that all dependencies are toward the center.
Turn your attention to the ConferenceRepository and UserSession classes. Notice that they are in layers outside of the application core, and they depend on the interfaces as well, so that they can implement them. These two classes each implement an interface closer to the center than itself. At runtime, our Inversion of Control container will look at its registry and construct the proper classes to satisfy the constructor dependencies of SpeakerController, which is the following:
public SpeakerController(IConferenceRepository conferenceRepository,
IUserSession userSession, IClock clock)
: base(userSession)
{
_conferenceRepository = conferenceRepository;
_clock = clock;
_userSession = userSession;
}
At runtime, the IoC container will resolve the classes that implement interfaces and pass them into the SpeakerController constructor. At this point in time, the SpeakerController can do its job.
Based on the rules of the Onion Architecture, the SpeakerController _could_ use UserSession directly since it's in the same layer, but it cannot use ConferenceRepository directly. It must rely on something external passing in an instance of IConferenceRepository. This pattern is used throughout, and the IoC container makes this process seamless.
At the end of this series, I plan on publishing a full working system that adheres to the Onion Architecture pattern. The systems we build for clients use this approach, but I'm not at liberty to discuss that code, so I will craft a reference application for those of you who prefer a concrete Visual Studio solution to digest.
架构:The Onion Architecture : part 2(洋葱架构:第二篇)(转载)的更多相关文章
- 企业架构研究总结(38)——TOGAF架构能力框架之架构能力建设和架构治理
为了确保架构功能在企业中能够被成功地运用,企业需要通过建立适当的组织结构.流程.角色.责任和技能来实现其自身的企业架构能力,而这也正是TOGAF的架构能力框架(Architecture Capabil ...
- 架构:The Onion Architecture : part 3(洋葱架构:第三篇)(转载)
In my previous installments, I described what has become my approach to defining the architecture fo ...
- 架构:The Onion Architecture : part 1(洋葱架构:第一篇)(转载)
原文地址:http://jeffreypalermo.com/blog/the-onion-architecture-part-1/. I've spoken several times about ...
- 干净的架构The Clean Architecture
干净的架构The Clean Architecture 这是著名软件大师Bob大叔提出的一种架构,也是当前各种语言开发架构.干净架构提出了一种单向依赖关系,从而从逻辑上形成一种向上的抽象系统. 我们经 ...
- 企业架构(Enterprise Architecture)
ylbtech-Miscellaneos: 企业架构(Enterprise Architecture) A,返回顶部 1, 简称EA.是指对企业事业信息管理系统中具有体系的.普遍性的问题而提供的通用解 ...
- [Architecture Design] 3-Layer基础架构
[Architecture Design] 3-Layer基础架构 三层式体系结构 只要是软件从业人员,不管是不是本科系出身的,相信对于三层式体系结构一定都不陌生.在三层式体系结构中,将软件开发所产出 ...
- 清晰架构(Clean Architecture)的Go微服务: 程序结构
我使用Go和gRPC创建了一个微服务,并试图找出最佳的程序结构,它可以用作我未来程序的模板. 我有Java背景,并发现自己在Java和Go之间挣扎,它们之间的编程理念完全不同.我写了一系列关于在项目工 ...
- 清晰架构(Clean Architecture)的Go微服务: 设计原则
我最近写了一个Go微服务应用程序,这个程序的设计来自三个灵感: 清晰架构"Clean Architecture"¹ and SOLID (面向对象设计)² 设计 原则³ Sprin ...
- 清晰架构(Clean Architecture)的Go微服务: 程序容器(Application Container)
清晰架构(Clean Architecture)的一个理念是隔离程序的框架,使框架不会接管你的应用程序,而是由你决定何时何地使用它们.在本程序中,我特意不在开始时使用任何框架,因此我可以更好地控制程序 ...
随机推荐
- mybatis SQL构造器
org.apache.ibatis.jdbc.AbstractSQL<T> org.apache.ibatis.jdbc.AbstractSQL<T> 抽象泛型类,它主要用于解 ...
- laravel 批量更新
/** * 转发动态和资讯数量统计 */ public function forwardCounts(FeedModel $feedModel) { //统计动态转发的id $feeds=$feedM ...
- (四)Dubbo Admin管理控制台
Dubbo Admin管理控制台 在dubbo2.6.0往后的版本在dubbo发布包中就没有dubbo-admin了,而是在incubator-dubbo-ops(https://github.com ...
- .NetCore下使用Prometheus实现系统监控和警报 (四)客户端代码处理
在代码中使用就比较简单了 Nuget包获取下 prometheus-net prometheus-net.AspNetCore 然后添加中间件就行了 app.UseMetricServer(); 默认 ...
- [转] 对vuex的表象理解(笔记)
一个东西,首先要知道为什么用它,为什么要vuex,官方解释为了解决繁杂事件订阅和广播,那么事件的$dispatch,$on,怎么就复杂了?许多人是不是感觉后者还挺简单的,对的 如果简单小型项目,那么不 ...
- Git(四)Git的分支管理
一. 创建合并分支原理 在我们每次的提交,Git都把它们串成一条时间线,这条时间线就是一个分支.截止到目前,只有一条时间线,在Git里,这个分支叫主分支,即master分支.HEAD指针严格来说不是指 ...
- 【LOJ】#2495. 「AHOI / HNOI2018」转盘
题面 题解 考虑我肯定是从一个人出发,开始依次标记,而不会跳过某个人,因为如果我跳过了,那么我之后回来还需要标记它,比不上我等完它再一直走到最后(因为多了走一圈之后走回它的代价) 我们倍长整个序列,我 ...
- LOOPS 概率dp
题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望 简单概率dp 注意 原地不 ...
- 【Java】 子字符串的比较(substring的==与equal()使用)
public class Test { public static void main(String[] args) { String str1="good"; System.ou ...
- PLSQL Developer连接远程oracle配置
在windows机器上不想安装oracle或者oracle的客户端,我们怎么使用PLSQL Developer工具呢?答案如下: 环境 windows7 ...