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 application
Configuration.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 source
Configuration.Localization.Sources.Add(
new XmlLocalizationSource(
"SimpleTaskSystem",
HttpContext.Current.Server.MapPath("~/Localization/SimpleTaskSystem")
)
); //Configure navigation/menu
Configuration.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系统中心配置点创建样板文件。

ABP框架系列之四十九:(Startup-Configuration-启动配置)的更多相关文章

  1. ABP框架系列之三十九:(NLayer-Architecture-多层架构)

    Introduction Layering of an application's codebase is a widely accepted technique to help reduce com ...

  2. ABP框架系列之四十四:(OWIN)

    If you are using both of ASP.NET MVC and ASP.NET Web API in your application, you need to add Abp.Ow ...

  3. ABP框架系列之四十:(Notification-System-通知系统)

    Introduction Notifications are used to inform users on specific events in the system. ASP.NET Boiler ...

  4. ABP框架系列之四十六:(Setting-Management-设置管理)

    Introduction Every application need to store some settings and use these settings in somewhere in th ...

  5. ABP框架系列之四十二:(Object-To-Object-Mapping-对象映射)

    Introduction It's a common to map a similar object to another object. It's also tedious and repeatin ...

  6. ABP框架系列之十九:(Debugging-调试)

    While it's not generally needed, you may want to step into ABP's source code while you debugging you ...

  7. ABP框架系列之四十八:(Specifications-规范)

    Introduction Specification pattern is a particular software design pattern, whereby business rules c ...

  8. ABP框架系列之四十五:(Quartz-Integration-Quartz-集成)

    Introduction Quartz is a is a full-featured, open source job scheduling system that can be used from ...

  9. 14.6.1 InnoDB Startup Configuration 启动配置

    14.6.1 InnoDB Startup Configuration 启动配置 首先描述关于InnoDB 配置设计数据库文件,日志文件,page size 和内存buffer 的配置. 推荐你定义数 ...

随机推荐

  1. Program type already present: android.support.v4.widget.EdgeEffectCompat

    1.确保所有依赖包的 implementation 'com.android.support:appcompat-v7:25.4.0'是一样的 2.确保最外层的build.gradle中增加如下代码: ...

  2. c#继承 里氏转化原则

    继承: 是c#中面向对象一个重要概念: 用一个已经存在的类去定义一个新的类 新的类叫做   子类/派生类 已经存在的类叫做   父类/基类 c#中所以类的最终基类都是Object类 声明 访问修饰符  ...

  3. vmware中的linux虚拟机配置以nat模式上网,并用xshell连接该虚拟机

    1.  首先确保宿主机上的vmnet8处于启用状态 2.  以管理员身份运行vmware >> 编辑 >> 虚拟机网络编辑器 >> 选中Vmnet8 >> ...

  4. CSV文件乱码展示(编码格式问题)

    最开始mac上打开CSV文件乱码,是这样的:CSV文件编码格式为UTF-8 解决办法一:将excel文件同样的转换编码格式为utf-8,具体操作如下: 去掉tab,勾选comma 最后,将文件另存为u ...

  5. android 开发 View _15 导入一张图片将它裁剪成圆形 与 paint图层叠加处理详解

    方法一: /* 实现思维是这样的: 1.首先拿到bitmap图片 2.得到bitmap图片的高度 宽度,并且计算好各个画图尺寸 3.创建一个空白的 bitmap图片: Bitmap output = ...

  6. 优化 SQL SELECT 语句性能

    SELECT语句的性能调优有时是一个非常耗时的任务,在我看来它遵循帕累托原则.20%的努力很可能会给你带来80%的性能提升,而为了获得另外20%的性能提升你可能需要花费80%的时间. 检查索引:在SQ ...

  7. canal 结合 kafka 入门

    1.kafka的安装: 略 2.cannal  配置 使用卡夫卡: 修改  /home/admin/canal-server/conf/canal.properties 2.1 修改canal.ser ...

  8. threading 多线程使用

    实例 1import threading #线程import time def Say(n): print('Test %d' %n) time.sleep(2) if __name__ == '__ ...

  9. Mybatis Generator 生成的mapper只有insert方法

    一般有两种情况 第一种是配置问题可以参考博客 http://blog.csdn.net/angel_xiaa/article/details/52474022 第二种是mysql-connector- ...

  10. jQuery的appendTo案例

    案例要求:点击双击第一个下拉列表框的选项可以把对应选项移到第二个下拉列表框中,选中第一个列表框的选项(可多选)单击-->按钮可使被选中项移动到右边下拉列表框中,单击==>按钮时将左边的所有 ...