.netCore中增加多个WebApi应用,将不同功能的应用分开,减少彼此的依赖,提高各模块的独立性和可维护性
1、新建文件夹,新建类库
2、建立Service下面的Module和领域基类
public class TaskBillServiceModule : AbpModule { public override void PreInitialize() { //非登录用户的审核日志是否保存 Configuration.Auditing.IsEnabledForAnonymousUsers = true; //是否允许多租户 Configuration.MultiTenancy.IsEnabled = true; } public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(TaskBillServiceModule).GetAssembly()); } }
/// <summary> /// Derive your application services from this class. /// </summary> public abstract class TaskBillServiceBase : DomainService { /* Add your common members for all your domain services. */ /*在领域服务中添加你的自定义公共方法*/ //// custom codes public CurrentUserInfo CurrentUserInfoProperty { get; set; } //// custom codes end protected TaskBillServiceBase() { LocalizationSourceName = PlatFormCoreConsts.LocalizationSourceName; } }
3、Application 中引用Service,创建App下面的module和领域基类,并在Module中添加对Service中Module的依赖
[DependsOn( typeof(TaskBillServiceModule), typeof(AbpAutoMapperModule))] public class TaskBillApplicationModule : AbpModule { private readonly IConfigurationRoot _appConfiguration; public TaskBillApplicationModule(IHostingEnvironment env) { } public override void PreInitialize() { } public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(TaskBillApplicationModule).GetAssembly()); } /// <summary> /// 获取配置文件权限相关信息 /// </summary> private void ConfigureTokenAuth() { } }
public abstract class TaskBillAppServiceBase : ApplicationService { public CurrentUserInfo CurrentUserInfoProperty { get; set; } protected TaskBillAppServiceBase() { LocalizationSourceName = PlatFormCoreConsts.LocalizationSourceName;
4、创建具体应用APP类,并添加对领域基类的依赖
public class DutyTaskBillApplication : TaskBillAppServiceBase, IDutyTaskBillApplication { public string GetDutyTask() { return "OK"; } }
运行,ok