feat:添加文档
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
## 简介
|
||||
通常,在Asp.NetCore中,**容器组装**过程 与 **管道模型组装** 过程 会将启动类文件变的非常长,同时也需要明确各个模块的依赖关系
|
||||
例如:
|
||||
我们需要仓储的功能,但是仓储的实现需要依赖Sqlsugar
|
||||
老的引入写法:
|
||||
``` cs
|
||||
service.AddUow();
|
||||
service.AddSqlsugar();
|
||||
......
|
||||
var app=service.Build();
|
||||
app.UseSqlsugar();
|
||||
......
|
||||
```
|
||||
这个文件会变得非常长,同时如果有顺序依赖关系的模块,还需按顺序组装
|
||||
例如:
|
||||
在Asp.NetCore,我们只有先鉴权才能进行授权操作
|
||||
当模块越来越多,我们维护起来将越来越困难,所以引入了模块化功能
|
||||
|
||||
## 使用
|
||||
每一个类库都可以有自己的模块化文件,我们通常命名为类库全名+Module
|
||||
例如:`Yi.Template.Application`的模块类叫做`YiTemplateApplicationModule`
|
||||
|
||||
另外,该模块类实现`AbpModule`基类
|
||||
ConfigureServices:用来配置容器服务
|
||||
OnApplicationInitialization:用来配置管道模型
|
||||
|
||||
Abp内置`DependsOn`特性标签,可进行维护各个模块之间的依赖关系
|
||||
|
||||
## 完整例子
|
||||
创建模块化文件:
|
||||
``` cs
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Abp.Domain;
|
||||
using Yi.Abp.SqlSugarCore;
|
||||
using Yi.Framework.Bbs.SqlSugarCore;
|
||||
using Yi.Framework.Mapster;
|
||||
using Yi.Framework.Rbac.SqlSugarCore;
|
||||
using Yi.Framework.SqlSugarCore;
|
||||
|
||||
namespace Yi.Abp.SqlsugarCore
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiAbpDomainModule),
|
||||
|
||||
typeof(YiFrameworkRbacSqlSugarCoreModule),
|
||||
typeof(YiFrameworkBbsSqlSugarCoreModule),
|
||||
|
||||
typeof(YiFrameworkMapsterModule),
|
||||
typeof(YiFrameworkSqlSugarCoreModule)
|
||||
)]
|
||||
public class YiAbpSqlSugarCoreModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
context.Services.AddYiDbContext<YiDbContext>();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
在启动管道模型组装文件使用入口模块:
|
||||
|
||||
Reference in New Issue
Block a user