Anley.DomainDrivenDesign.Contract
1.2.1
dotnet add package Anley.DomainDrivenDesign.Contract --version 1.2.1
NuGet\Install-Package Anley.DomainDrivenDesign.Contract -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
For projects that support PackageReference, copy this XML node into the project file to reference the package.
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Anley.DomainDrivenDesign.Contract --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Anley.DomainDrivenDesign.Contract, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Anley.DomainDrivenDesign.Contract@1.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Anley.DomainDrivenDesign.Contract&version=1.2.1
#tool nuget:?package=Anley.DomainDrivenDesign.Contract&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Anley.DomainDrivenDesign.Contract
领域驱动设计程序契约类库。
一、Application
1、AneResult - 结果类
用于约束API接口返回标准的操作结果。
示例操作结果如下:
{
"code": 200,
"message": ""
}
其中,code为结果码,其可能为以下值:
| 代码 | 结果类型 |
|---|---|
| 200 | 成功 |
| 300 | 失败 |
| 400 | 语义有误 |
| 401 | 未认证 |
| 403 | 拒绝执行 |
| 404 | 数据不存在 |
| 408 | 请求超时 |
| 409 | 操作冲突 |
| 500 | 内部错误 |
2、AneResult - 含数据的结果类
用于约束含数据的API接口返回标准的操作结果。
示例操作结果如下:
{
"data": {
"accessToken": "token",
"expireMinutes": 120
},
"code": 200,
"message": ""
}
3、FriendlyException - 友好异常类
用于抛出自定义业务异常。
实例化友好异常时,NLog将自动记录异常。
4、GlobalExceptionFilter - 全局异常处理类
全局异常捕捉,并返回符合AneResult标准的结果。其中,code值为500。
二、Authorization
1、AuthorizationHelper - 授权帮助类
- GenerateAccessToken():生成访问令牌(
JWT),加密方式为国密SM2算法。 - VerifyAccessToken():验证访问令牌(
JWT),返回当前用户
2、AuthorizationMiddleware - 授权中间件
授权验证。请求API接口时,请将访问令牌存储于Headers-Authorization中,格式为:Bearer {token}或{token}。
授权验证支持白名单机制,请在appsettings.json中添加配置:
{
"Authorization": {
"TokenExpire": 120,
"AnonymousPaths": [
"/swagger",
"/heart",
"/images",
"/api/Login",
"/api/Register"
]
}
}
3、ICurrentUser - 当前用户接口
请在项目中继承该接口,以实现访问令牌中的身份识别。
继承该接口时,可以增加自定义字段,字段值将存储于访问令牌中,请勿存储敏感数据。
三、Configuration
1、ConfigurationExtension - 配置扩展类
- Configuration:获取配置
- RegisterConfiguration():注册配置
2、AuthorizationConfiguration - 授权配置
- TokenExpire:Token有效期(单位:分钟),默认为120分钟
- AnonymousPaths:可匿名访问路径
3、EncryptionConfiguration - 加密配置
- SM2Server:国密SM2服务端密钥
- SM2Client:国密SM2客户端密钥
- SM3:国密SM3密钥
- SM4:国密SM4密钥
四、DependencyInjection
继承自本目录下的所有类将自动进行依赖注入。
| 接口/类 | 功能 |
|---|---|
| IScopedAutoInject | 范围内自动注入接口 |
| ISingletonAutoInject | 单例自动注入接口 |
| ITransientAutoInject | 临时自动注入接口 |
| ISelfScopedAutoInject | 范围内自动自注入接口 |
| ISelfSingletonAutoInject | 单例自动自注入接口 |
| ISelfTransientAutoInject | 临时自动自注入接口 |
| MappingProfile | 映射配置抽象类 |
五、Domain
| 接口/类 | 功能 |
|---|---|
| IEntity/Entity | 实体接口/实体类 |
| ICreatableEntity/CreatableEntity | 可创建实体接口/可创建实体类 |
| IUpdatableEntity/UpdatableEntity | 可更新实体接口/可更新实体类 |
| IDeletableEntity | 可删除实体接口 |
| IAggregateRoot/AggregateRoot | 聚合根接口/聚合根类 |
| ValueObject | 值对象抽象类 |
六、DomainAdapter
| 类 | 功能 |
|---|---|
| PagedVo | 分页查询视图对象抽象类 |
| PagedDto | 分页数据传输对象 |
| SelectorOption | 选择器选项 |
七、Enums
| 类 | 功能 |
|---|---|
| AneResultCode | 结果码枚举 |
| FileExtensions | 文件扩展类枚举 |
八、Extension
| 类 | 功能 |
|---|---|
| ArrayExtension | 数组扩展类 |
| ByteExtensions | 字节扩展类 |
| CheckExtension | 检查扩展类 |
| DateTimeExtension | 日期时间扩展类 |
| EntityExtension | 实体扩展类 |
| EnumExtension | 枚举扩展类 |
| ListExtension | 列表扩展类 |
| ObjectExtensions | 对象扩展类 |
| StringExtension | 字符扩展类 |
| TypeExtension | 类型扩展类 |
九、Helper
| 接口/类 | 功能 |
|---|---|
| IEncryptionHelper/EncryptionHelper | 加密帮助类 |
| IFileHelper/FileHelper | 文件帮助类 |
| IGuidGenerator/GuidGenerator | 标识帮助类 |
| IHostHelper/HostHelper | 主机帮助类 |
| IHttpHelper/HttpHelper | 网络请求帮助类 |
| IMailHelper/MailHelper | 邮件帮助类 |
| IRandomHelper/RandomHelper | 随机帮助类 |
| IVerifyHelper/VerifyHelper | 验证帮助类 |
| ServiceProviderHelper | 服务提供程序帮助类 |
十、Infrastructure
| 接口/类 | 功能 |
|---|---|
| IRepository/Repository | 仓储接口/仓储抽象类 |
| IRepositoryContext | 仓储上下文接口 |
| SqlServerRepositoryContext | SQLServer仓储上下文类 |
| MySqlRepositoryContext | MySQL仓储上下文类 |
| IRepositoryContextProvider | 仓储上下文提供程序接口 |
| SqlServerRepositoryContextProvider | SqlServer仓储上下文提供程序类 |
| MySqlRepositoryContextProvider | MySQL仓储上下文提供程序类 |
十一、Swagger
| 类 | 功能 |
|---|---|
| HiddenApiAttribute | 隐藏Swagger接口特性 |
十二、其他
| 类 | 功能 |
|---|---|
| AneConsts | 常量类 |
| HostExtension | 主机扩展类 |
HostExtension包含的扩展方法如下:
- RegisterDependencyInjection:注册依赖注入
- RegisterAutoMapper:注册AutoMapper
- ConfigureModelState:配置模型状态
- RegisterCors:注册跨域
- ConfigureForwardedHeaders:配置转发头(读取客户端真实IP地址)
- UseSqlServer:使用SqlServer数据库
- UseMySql:使用MySql数据库
- RegisterSwagger:注册Swagger
- RegisterLocalization:注册本地化
- RegisterExceptionHandling:注册异常处理
- RegisterModelValidation:注册模型验证
- RegisterNewtonsoftJson:注册JSON
- RegisterNLog:注册NLog
- ApplyDependencyInjection:应用依赖注入
- ApplyCors:应用跨域
- ApplyForwardedHeaders:应用转发头
- ApplyAuthorization:应用授权
- ApplyLocalization:应用本地化
- ApplySwagger:应用Swagger
- ApplyStaticFiles:应用静态文件
- ApplyRoute:应用路由
示例代码如下:
public class Program
{
public static void Main(string[] args)
{
// 读取配置
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Services.RegisterConfiguration();
#region 配置主机端口
var host = configuration["Site:Host"] ?? "http://localhost";
var port = int.Parse(configuration["Site:Port"] ?? "5000");
builder.WebHost.ConfigureKestrel(opt =>
{
opt.ListenAnyIP(port);
});
builder.WebHost.UseUrls($"{host}:{port}");
#endregion
builder.Services
.RegisterDependencyInjection() // 注册依赖注入
.RegisterAutoMapper() // 注册AutoMapper
.RegisterCors() // 允许跨域
.ConfigureForwardedHeaders() // 配置转发头
.UseSqlServer(
connectionStringName: "Shop") // 使用SqlServer数据库
.RegisterSwagger(
"Shop Apis",
"v1",
"Shutter.Domain.xml") // 注册Swagger
.RegisterLocalization(); // 注册本地化
builder.Services.AddControllersWithViews(opt =>
{
opt.RegisterExceptionHandling(); // 注册异常处理
// 注册模型验证
opt.RegisterModelValidation(
"Shutter.DomainAdapter",
"Shutter.DomainAdapter.Resources.DataAnnotations");
}) // 注册控制器
.RegisterNewtonsoftJson(); // 注册JSON
builder.Services.ConfigureModelState(); // 配置模型验证
builder.RegisterNLog(); // 注册NLog
var app = builder.Build();
app.ApplyDependencyInjection(); // 应用依赖注入
app.ApplyCors() // 应用跨域
.ApplyForwardedHeaders() // 应用转发头
.UseHttpsRedirection() // HTTPS重定向
.ApplyStaticFiles(
FileExtensions.Png,
FileExtensions.JPG) // 应用静态文件
.ApplyAuthorization() // 应用授权
.ApplyLocalization(
AneConsts.DefaultCultureName,
"en-US") // 本地化
.ApplySwagger(
"Shop Apis V1",
"v1"); // 应用Swagger
app.ApplyRoute(); // 应用路由
app.Run(); // 运行
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Aspose.PDF (>= 25.4.0)
- Aspose.Words (>= 25.5.0)
- AutoMapper (>= 14.0.0)
- BouncyCastle.Cryptography (>= 2.5.1)
- Dapper (>= 2.1.66)
- Dapper.Contrib (>= 2.0.78)
- IP2Region.Net (>= 2.0.2)
- MailKit (>= 4.12.0)
- Microsoft.Data.SqlClient (>= 6.0.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Http.Polly (>= 9.0.4)
- Microsoft.Extensions.Localization (>= 9.0.4)
- MiniExcel (>= 1.41.1)
- NLog (>= 5.4.0)
- NLog.Web.AspNetCore (>= 5.4.0)
- Scrutor (>= 6.0.1)
- StackExchange.Redis (>= 2.8.37)
- Swashbuckle.AspNetCore.Newtonsoft (>= 8.1.1)
- Swashbuckle.AspNetCore.Swagger (>= 8.1.1)
- Swashbuckle.AspNetCore.SwaggerGen (>= 8.1.1)
- Swashbuckle.AspNetCore.SwaggerUI (>= 8.1.1)
- Z.Dapper.Plus (>= 7.5.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.1 | 334 | 5/11/2025 |
| 1.1.8.1 | 331 | 4/15/2025 |
| 1.1.8 | 241 | 4/13/2025 |
| 1.1.7 | 245 | 4/13/2025 |
| 1.1.6.1 | 245 | 4/13/2025 |
| 1.1.6 | 194 | 4/12/2025 |
| 1.1.5 | 316 | 4/7/2025 |
| 1.1.4.1 | 281 | 4/2/2025 |
| 1.1.4 | 267 | 4/1/2025 |
| 1.1.2.3 | 332 | 3/4/2025 |
| 1.1.2.2 | 333 | 3/4/2025 |
| 1.1.2.1 | 243 | 1/25/2025 |
| 1.1.2 | 242 | 1/25/2025 |
| 1.1.1.1 | 240 | 1/24/2025 |
| 1.1.1 | 233 | 1/19/2025 |
| 1.0.3.2 | 234 | 1/19/2025 |
| 1.0.3.1 | 267 | 12/30/2024 |
| 1.0.3 | 258 | 12/19/2024 |
| 1.0.2 | 282 | 12/14/2024 |
| 1.0.1 | 275 | 12/14/2024 |
Loading failed