ASP.NET Boilerplate provides an infrastructure and a model to configure it and modules on startup.

ASP.NET提供了一个基础和样板模型配置和模块启动。

Configuring ASP.NET Boilerplate

Configuring ASP.NET Boilerplate is made on PreInitialize event of your module. Example configuration:

配置ASP.NET样板在模块的PreInitialize 事件里。配置示例:

public class SimpleTaskSystemModule : AbpModule
{public override void PreInitialize(){//Add languages for your applicationConfiguration.Localization.Languages.Add(new LanguageInfo("en", "English", "famfamfam-flag-england", true));Configuration.Localization.Languages.Add(new LanguageInfo("tr", "Türkçe", "famfamfam-flag-tr"));//Add a localization sourceConfiguration.Localization.Sources.Add(new XmlLocalizationSource("SimpleTaskSystem",HttpContext.Current.Server.MapPath("~/Localization/SimpleTaskSystem")));//Configure navigation/menuConfiguration.Navigation.Providers.Add<SimpleTaskSystemNavigationProvider>();        }public override void Initialize(){IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());}
}

ASP.NET Boilerplate is designed modularity in mind. Different modules can configure ASP.NET Boilerplate. For example, different modules can add navigation provider to add their own menu items to the main menu. (Seelocalization and navigation documents for details on configuring them).

ASP.NET样板设计模块化的思想。不同的模块可以配置ASP.NET样板。例如,不同的模块可以添加导航提供程序,将自己的菜单项添加到主菜单中。(在它们配置细节seelocalization导航文件)。

Replacing Built-In Services(替换内置服务)

Configuration.ReplaceService method can be used to override a built-in service. For example, you can replace IAbpSession service with your custom implementation as shown below:

configuration.replaceservice方法可用于重写内置服务。例如,您可以与您的自定义实现替代iabpsession服务如下图所示:

Configuration.ReplaceService<IAbpSession, MySession>(DependencyLifeStyle.Transient);

ReplaceService method has an overload to pass an action to make replacement in a custom way (you can directly use Castle Windsor for advanced registration API).

replaceservice方法具有过载通过一个自定义的方式做替代动作(可以直接使用Castle Windsor 高级注册API)。

Same service can be replaced multiple times (especially, in different modules). Last replaced will be valid (As you know, module PreInitialize methods are executed by dependency order).

同样的服务可以多次更换(特别是在不同的模块中)。最后更换将是有效的(你知道,模块分发方法是通过依赖顺序执行)。

Configuring Modules(配置模块)

Beside framework's own startup configuration, a module can extend IAbpModuleConfigurations interface to provide configuration points for the module. Example:

在框架的启动配置,一个模块可以扩展iabpmoduleconfigurations接口提供的模块配置点。例子:

...
using Abp.Web.Configuration;
...
public override void PreInitialize()
{Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;
}
...

In this example, we configured AbpWebCommon module to send all exceptions to clients.

在这个例子中,我们配置abpwebcommon模块发送给客户的所有异常。

Not every module should define this type of configuration. It's generally needed when a module will be re-usable in different applications and needs to be configured on startup.

不是每个模块都应该定义这种类型的配置。当一个模块在不同的应用程序中重新使用,并且需要在启动时进行配置时,这通常是必需的。

Creating Configuration For a Module(创建一个模块配置)

Assume that we have a module named MyModule and it has some configuration properties. First, we create a class for these cofigurable properties:

假设我们有一个模块叫MyModule,它有一些配置属性。首先,我们创建一个可配置特性这类:

public class MyModuleConfig
{public bool SampleConfig1 { get; set; }public string SampleConfig2 { get; set; }
}

Then we register this class to Dependency Injection on PreInitialize event of MyModule (Thus, it will be injectable):

然后我们登记这类依赖注入在起始事件mymodule(因此,它将注射):

IocManager.Register<MyModuleConfig>();

It should be registered as Singleton as in this sample. Now, we can use the following code to configure MyModule in our module's PreInitialize method:

它应该像本示例一样注册为单例。现在,我们可以使用下面的代码在我们的模块的配置MyModule的起始方法:

Configuration.Get<MyModuleConfig>().SampleConfig1 = false;

While we can use IAbpStartupConfiguration.Get method as shown below, we can create an extension method to IModuleConfigurations like that:

我们可以用iabpstartupconfiguration。获取方法如下图所示,我们可以创造imoduleconfigurations这样的扩展方法:

public static class MyModuleConfigurationExtensions
{public static MyModuleConfig MyModule(this IModuleConfigurations moduleConfigurations){return moduleConfigurations.AbpConfiguration.Get<MyModuleConfig>();}
}

Now, other modules can configure this module using the extension method:

现在,其他模块可以使用扩展方法配置这个模块:

Configuration.Modules.MyModule().SampleConfig1 = false;
Configuration.Modules.MyModule().SampleConfig2 = "test";

This makes easy to investigate module configurations and collect them in a single place (Configuration.Modules...). ABP itself defines extension methods for it's own module configurations.

At some point, MyModule needs to this configuration. You can inject MyModuleConfig and use configured values. Example:

这便于调查模块配置,并在单个位置收集它们(配置……)。ABP本身为其自己的模块配置定义了扩展方法。

在某一点上,MyModule需要这样的配置。你可以把MyModuleConfig和使用配置值。例子:

public class MyService : ITransientDependency
{private readonly MyModuleConfig _configuration;public MyService(MyModuleConfig configuration){_configuration = configuration;}public void DoIt(){if (_configuration.SampleConfig2 == "test"){//...}}
}

Thus, modules can create central configuration points in ASP.NET Boilerplate system.

因此,模块可以在ASP.NET系统中心配置点创建样板文件。

转载于:https://www.cnblogs.com/smileberry/p/8296996.html

ABP框架系列之四十九:(Startup-Configuration-启动配置)相关推荐

  1. 软考高级信息系统项目管理师系列之四十九:量化的项目管理

    软考高级信息系统项目管理师系列之四十九:量化的项目管理 一.量化的项目管理内容 二.量化的项目管理概述 三.量化的项目管理过程 四.量化的项目管理工具 量化的项目管理涉及单项选择题类型,分值为1分左右 ...

  2. ABP框架系列之十四:(Background-Jobs-And-Workers-背景工作和工人)

    Introduction ASP.NET Boilerplate provides background jobs and workers those are used to execute some ...

  3. ABP框架系列之三十:(Javascript-API-Javascript-API)

    ASP.NET Boilerplate provides a set of objects and functions that are used to make javascript develop ...

  4. 网络安全系列之三十九 在Linux中配置访问控制列表ACL

    Linux系统中传统的权限设置方法比较简单,仅有3种身份.3种权限而已,通过配合chmod和chown等命令来对文件的权限或所有者进行设置.如果要进行比较复杂的权限设定,例如某个目录要开放给某个特定的 ...

  5. 网络安全系列之四十六 在IIS6中配置目录安全性

    Web站点默认是允许匿名访问的,某些特殊网站(或者虚拟目录)如果要求用户提供账号和密码才能访问,或者限定某些IP地址能(或不能)访问,那可以通过在Web站点属性的"目录安全性"选项 ...

  6. 微服务接入oauth2_SpringCloud微服务实战系列(十九)Ouath2在真实场景中的应用之客户端接入(第一种写法)...

    SpringCloud微服务实战系列(十九)Ouath2在真实场景中的应用之客户端接入(第一种写法) 一.概述 在<SpringCloud微服务实战系列(十七)Ouath2在真实场景中的应用之资 ...

  7. SAP UI5 应用开发教程之四十九 - 如何在桌面电脑端调试运行在手机上的 SAP UI5 应用试读版

    一套适合 SAP UI5 初学者循序渐进的学习教程 教程目录 SAP UI5 本地开发环境的搭建 SAP UI5 应用开发教程之一:Hello World SAP UI5 应用开发教程之二:SAP U ...

  8. 老周的ABP框架系列教程

    老周的ABP框架系列教程 -- 一.框架理论初步学习   1. ABP框架的来源与作用简介 1.1  简介 1.1.1       ABP框架全称为"ASP.NET Boilerplate ...

  9. PVE系列教程(十九)、ubuntu22.04使用Nginx配置chevereto服务器

    PVE系列教程(十九).ubuntu22.04使用Nginx配置chevereto服务器 为了更好的浏览体验,欢迎光顾勤奋的凯尔森同学个人博客http://www.huerpu.cc:7000 一.环 ...

  10. 软考高级信息系统项目管理师系列之四十五:信息系统综合测试与管理

    软考高级信息系统项目管理师系列之四十五:信息系统综合测试与管理 一.信息系统综合测试与管理 二.软件测试模型 1.V模型 2.W模型 3.H模型 4.X模型 5.前置测试模型 三.软件测试类型 1.按 ...

最新文章

  1. SPU、SKU、ARPU是什么,我来记录一下我的理解
  2. 从抵触到力推,.Net Core 的成功让微软正视开源
  3. php数组地址,怎么实现javascript数组与php数组的地址传递
  4. Spring Boot的exit code
  5. 如何查看一个现有的keil工程之前由什么版本的keil IDE编译
  6. 每月1000元存入余额宝或银行,十年后会有多少?
  7. 关于 NIO 你不得不知道的一些“地雷”
  8. Django 文件上传与下载的相关问题
  9. Android studio 报错Failed to open zip file解决方法
  10. 【Python】Python IDLE 设置清屏功能(清屏快捷键Ctrl+w,亲测通用)
  11. c语言中debug的作用,c语言debug怎么用
  12. 2018款联想Y7000 黑苹果外接显示器方案
  13. PHP为什么是最好的编程语言?
  14. Python学习笔记-2017.5.4thon学习笔记-2017.5.14
  15. doctrine-orm基础(单用doctrine避坑指南)
  16. vue项目运行后页面一片空白
  17. 企业上云的动力是什么
  18. windows7蓝牙怎么打开_【windows7】IP地址查询方法
  19. C语言中.h开头文件的书写和用法
  20. 电信智能手机android,电信智能手机推荐【图文】

热门文章

  1. [C++]最大连续子序列乘积
  2. 网站成功的三十三个法则
  3. 给DateField和DateChooser进行汉化
  4. Velocity-模板引擎(代码生成等)
  5. font-spider(字蛛) 让页面引入中文web字体
  6. SpringCloud+Seata+nacos案例(包含源码 Seata及nacos安装教程)
  7. 24. Declear non-member functions when type conversions should apply to all parameters
  8. python适用于哪些芯片_这些鲜为人知的Python功能,你值得拥有!
  9. python aes加密对于长字符数据丢失_Python 3中AES加密和解密的字符串字节数
  10. request与在php安全,request导致的安全性问题分析