NLayerAppV3--基础结构层(Cross-Cutting部分)
回顾:NLayerAppV3是一个使用.net 2.1实现的经典DDD的分层架构的项目。
NLayerAppV3是在NLayerAppV2的基础上,使用.net core2.1进行重新构建的;它包含了开发人员和架构师都可以重用的DDD层。
Github地址:https://github.com/cesarcastrocuba/nlayerappv3
NLayerAppV3的基础结构层一共分为两个部分。处理数据相关的基础组件和Cross-Cutting的基础组件。
处理数据相关的基础组件主要包含UOW和仓储的实现;
Cross-Cutting的基础组件目前主要包含数据适配器、国际化、验证;
本节我们主要介绍Cross-Cutting的基础组件。
这部分相关的项目主要有两个Infrastructure.Crosscutting和Infrastructure.Crosscutting.NetFramework。
Infrastructure.Crosscutting封装了数据适配器、国际化、验证相关的接口;
Infrastructure.Crosscutting.NetFramework包含了Infrastructure.Crosscutting中相关契约的实现;
1、Infrastructure.Crosscutting
--Adapter数据适配器
这部分是数据适配或者数据转换的功能契约。
数据转换是什么?为什么要数据转换?
DTO:数据转换对象。
数据转换主要是用于将用户的输入转换为DTO,在持久化的时候又将DTO转为领域模型进行持久化;如果是用户请求数据的话,则是相反的过程。
首先定义了一个类型转换的契约ITypeAdapter。
接口中定义了类型转换的方法,给我一个TSource,我还你一个TTarget。
TTarget Adapt<TSource, TTarget>(TSource source)
where TTarget : class, new()
where TSource : class;
ITypeAdapterFactory是适配器的工厂契约
ITypeAdapter Create();
创建适配器,返回适配器的契约。
TypeAdapterFactory是适配器工厂。
静态类,有两个方法,设置当前工厂和创建适配器的方法。
static ITypeAdapterFactory _currentTypeAdapterFactory = null;
#endregion
#region Public Static Methods
/// <summary>
/// Set the current type adapter factory
/// </summary>
/// <param name="adapterFactory">The adapter factory to set</param>
public static void SetCurrent(ITypeAdapterFactory adapterFactory)
{
_currentTypeAdapterFactory = adapterFactory;
}
/// <summary>
/// Create a new type adapter from currect factory
/// </summary>
/// <returns>Created type adapter</returns>
public static ITypeAdapter CreateAdapter()
{
return _currentTypeAdapterFactory.Create();
}
--Localization 国际化
结构跟Adapter类似。
ILocalization定义了国际化的契约。
public interface ILocalization
{
string GetStringResource(string key);
string GetStringResource(string key, CultureInfo culture);
string GetStringResource<T>(T key) where T : struct, IConvertible;
string GetStringResource<T>(T key, CultureInfo culture) where T : struct, IConvertible;
}
GetStringResource:根据key和CultureInfo获取value。
ILocalizationFactory是创建国际化的工厂。
LocalizationFactory是国际化的工厂。
有两个方法,创建当前国际化的工厂SetCurrent和创建当前资源的CreateLocalResources。
LocalizationKeys定义了资源的枚举。
--Validator 验证
结构跟Adapter类似。
IEntityValidator实体验证的契约。
包含两个方法:是否验证IsValid和获取验证信息集GetInvalidMessages。
/// <summary>
/// Perform validation and return if the entity state is valid
/// </summary>
/// <typeparam name="TEntity">The type of entity to validate</typeparam>
/// <param name="item">The instance to validate</param>
/// <returns>True if entity state is valid</returns>
bool IsValid<TEntity>(TEntity item)
where TEntity : class; /// <summary>
/// Return the collection of errors if entity state is not valid
/// </summary>
/// <typeparam name="TEntity">The type of entity</typeparam>
/// <param name="item">The instance with validation errors</param>
/// <returns>A collection of validation errors</returns>
IEnumerable<String> GetInvalidMessages<TEntity>(TEntity item)
where TEntity : class;
IEntityValidatorFactory是实体验证工厂的契约。
定义了一个创建方法。
EntityValidatorFactory是实体验证工厂。
有两个方法,一个是设置当前工厂SetCurrent,另一个是创建验证器CreateValidator。
static IEntityValidatorFactory _factory = null;
#endregion
#region Public Methods
/// <summary>
/// Set the log factory to use
/// </summary>
/// <param name="factory">Log factory to use</param>
public static void SetCurrent(IEntityValidatorFactory factory)
{
_factory = factory;
}
/// <summary>
/// Create the validator factory
/// </summary>
/// <returns></returns>
public static IEntityValidator CreateValidator()
{
return (_factory != null) ? _factory.Create() : null;
}
2、Infrastructure.Crosscutting.NetFramework
--Adapter 数据适配器
使用AutoMapper库实现了类型转换适配器。
AutomapperTypeAdapter实现了ITypeAdapter,完成了源目标数据类型到时目标数据类型的转换工作。
AutomapperTypeAdapterFactory实现了ITypeAdapterFactory。
在构造函数里使用反射的方式,加载Application层中的Profiler文件,实现类型转换的配置。
Create方法返回AutomapperTypeAdapter对象。
--Localization 国际化
ResourcesManager实现了ILocalization,完成了从资源文件读取信息实现国际化。
ResourcesManagerFactory实现了ILocalizationFactory。
Create方法返回了ResourcesManager对象。
Resources文件夹下放的是资源文件。
--Validator 验证
DataAnnotationsEntityValidator实现了IEntityValidator。
使用System.ComponentModel.DataAnnotations验证实体的正确性。
DataAnnotationsEntityValidatorFactory实现了IEntityValidatorFactory。
Create方法返回了DataAnnotationsEntityValidator对象。
总结:NLayerAppV3项目的Infrastructure(基础设施层)CrossCutting部分目前有三部分内容:适配器、国际化、验证。
定义了适配器、国际化、验证的契约以及它们的工厂;
实现了AutoMapper类型适配器、、国际化资源的获取、System.ComponentModel.DataAnnotations方式的实体验证。
参考:dax.net文章 https://www.cnblogs.com/daxnet/archive/2011/06/01/2067134.html
NLayerAppV3--基础结构层(Cross-Cutting部分)的更多相关文章
- NLayerAppV3-Infrastructure(基础结构层)的Data部分和Application(应用层)
回顾:NLayerAppV3是一个使用.net 2.1实现的经典DDD的分层架构的项目. NLayerAppV3是在NLayerAppV2的基础上,使用.net core2.1进行重新构建的:它包含了 ...
- 1、HA Cluster基础原理
Linux Cluster --> linux集群类型分三种: LB:负载均衡,LoadBalance HA:双机集群系统,指高可用性集群,High Available HP:Hadoop ...
- 零基础学习java------37---------mybatis的高级映射(单表查询,多表(一对一,一对多)),逆向工程,Spring(IOC,DI,创建对象,AOP)
一. mybatis的高级映射 1 单表,字段不一致 resultType输出映射: 要求查询的字段名(数据库中表格的字段)和对应的java类型的属性名一致,数据可以完成封装映射 如果字段和jav ...
- Spring Boot使用AOP实现REST接口简易灵活的安全认证
我们继续上一篇文章的分析,本文将通过AOP的方式实现一个相对更加简易灵活的API安全认证服务. 我们先看实现,然后介绍和分析AOP基本原理和常用术语. 一.Authorized实现 1.定义注解 pa ...
- Spring03-AOP
一. AOP介绍 1. Aop介绍 AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编 ...
- Dubbo x Cloud Native 服务架构长文总结(很全)
Dubbo x Cloud Native 服务架构长文总结(很全) mercyblitz SpringForAll社区 3天前 分享简介 Cloud Native 应用架构随着云技术的发展受到业界特别 ...
- Spring AOP详解和实现方式
一.什么是AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善. ...
- Spring系列(四):Spring AOP详解和实现方式(xml配置和注解配置)
参考文章:http://www.cnblogs.com/hongwz/p/5764917.html 一.什么是AOP AOP(Aspect Oriented Programming),即面向切面编程, ...
- NLayerAppV3--DDD之领域层
回顾:NLayerAppV3是一个使用.net 2.1实现的经典DDD的分层架构的项目. NLayerAppV3是在NLayerAppV2的基础上,使用.net core2.1进行重新构建的:它包含了 ...
随机推荐
- visual code golang配置
前言 其实环境搭建没什么难的,但是遇到一些问题,主要是有些网站资源访问不了(如:golang.org), 导致一些包无法安装,最终会导致环境搭建失败,跟据这个教程几步,我们将可以快速的构建golang ...
- 使用DW工具给图片添加热点MAP
一.准备一张图片. 准备一张需要给不同区域添加不同热点的图片. 二.插入图片: 打开Dreamweaver,新建一个网页,将图片插入到页面中. 三.找到地图工具: 单击鼠标左键点击图片,这时候 ...
- TZOJ 1242 求出前m大的数(预处理)
描述 给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=10000)并按从大到小的顺序排列. 输入 ...
- OC 线程操作 - GCD使用 -线程通讯, 延迟函数和一次性代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // [self downImag ...
- php的静态化
原理,将动态的页面,存储为静态的HTML静态页,使浏览器直接请求该静态页. 测试:一个PHP动态页面与一个静态页面所消耗的时间 一般可以使用apache自带的ab(apache bench)程序来测试 ...
- 如何区分USB 2.0 和USB 3.0插口
USB3.0的速度是USB2.0的十倍,并且比USB2.0更加节能,同时,还能向下兼容USB2.0.那么,我们怎么区分USB2.0 和 USB 3.0呢. 电脑(有USB2.0和USB3.0的插口) ...
- jstl $前 出现 空格 ,可能出现无法解析的 情况
<c:if test="${sessionScope.contactName == null || sessionScope.contactName==''}"> 能正 ...
- mysql 1045 access denied for user********
另一个方法Windows: 1. 管理员登陆系统,停止mysql服务或者结束mysqld-nt进程2. 进入命令行,来到mysql的安装目录.假设安装目录为 d:/mysql/ , CMD进入命令行3 ...
- XAMPP Apache + MariaDB + PHP + Perl
https://www.apachefriends.org/zh_cn/index.html 什么是XAMPP? XAMPP是最流行的PHP开发环境 XAMPP是完全免费且易于安装的Apache发行版 ...
- 2018.09.16 loj#10243. 移棋子游戏(博弈论)
传送门 题目中已经给好了sg图,直接在上面跑出sg函数即可. 最后看给定点的sg值异或和是否等于0就判好了. 代码: #include<bits/stdc++.h> #define N 2 ...