Click here to go to the ABP series articles General Catalogue
DDD-based Modern ASP.--ABP Series 5, ABP boot configuration
The ABP is "ASP. Boilerplate Project (ASP. NET Template project) "for short.
ABP's official website :http://www.aspnetboilerplate.com
ABP's Open source project on GitHub : https://github.com/aspnetboilerplate
This article is provided by Dongguan -Heaven translation
Note: Before looking at the content of this section, we recommend that you first download the Module-zero example code, this example is a user and role of the module, and the use of the instance. Configuration can be in every application, such as you have a website, you want to get some of the site's custom basic parameters, such as logo location, site name, upload file size and so on. Modular configuration and our previous approach is certainly different, we should pay attention to. Previously nothing was a method getconfig from the corresponding table to fetch data, and then use.
The ABP Framework provides the basic configuration and methods of the module before the app is launched, as you can see from the example below.
Configure ABP
The configuration is implemented by the Preinitialize method in its own module. (for module's Preinitialize method, in the previous article has already made the simple explanation to everybody)
The code examples are as follows:
Public classsimpletasksystemmodule:abpmodule{ Public Override voidpreinitialize () {//Add a language pack to your app, which is in English and the author's Turkish language. CONFIGURATION.LOCALIZATION.LANGUAGES.ADD (NewLanguageinfo ("en","中文版","Famfamfam-flag-england",true));CONFIGURATION.LOCALIZATION.LANGUAGES.ADD (NewLanguageinfo ("TR","Türkçe","famfamfam-flag-tr"));Configuration.Localization.Sources.Add (NewXmllocalizationsource ("Simpletasksystem", HttpContext.Current.Server.MapPath ("~/localization/simpletasksystem") ) ); //Configure navigation and menusConfiguration.navigation.providers.add<simpletasksystemnavigationprovider>(); } Public Override voidInitialize () {iocmanager.registerassemblybyconvention (assembly.getexecutingassembly ()); }}
Similar to orchard, the ABP framework was designed to be modular in the first place, and different modules can be configured via the ABP framework. For example, different modules can be added to the navigation, through the navigation to add menu items to their own definition of the main menu, the specific details you can refer to:
- Localization: http://www.aspnetboilerplate.com/Pages/Documents/Localization
- Navigation: http://www.aspnetboilerplate.com/Pages/Documents/Navigation
Configuration module
Compared to the native startup configuration of the. NET Framework, what are the different ABP? The modules of the ABP framework can be individually extended via the iabpmoduleconfigurations interface, which makes the module configuration simpler and more convenient.
The sample code is as follows:
... using Abp.Web.Configuration, ..... Public Override void preinitialize () { true;} ...
In the above example, we send an exception to the client by configuring the Abpweb module. Of course, not every module requires this configuration, and usually we need to do this when a module needs to be reused in several different applications.
Creating a configuration for a module
The following code, if we have a module named MyModule, and this module has some of its own configuration. So we'll start by creating classes that are defined as attributes (the Translator notes: properties have automatic get and set accessors.) ), which represents a different configuration.
Public class mymoduleconfig{ publicboolgetset;} Public string Get Set ; }}
Next, we register this class through dependency injection.
Iocmanager.register<mymoduleconfig> (); //Translator Note: A class is registered in Iocmanager, in other words, we can get an instance of this class mymoduleconfig by Iocmanager. As for the IOC principle, it is not detailed here, in short, it is possible to get an instance of a class.
Finally, we get a reference to the configuration by creating an extended method, imoduleconfigurations. The following code:
Translator Note: The module configuration is a static class, because we need to reuse it. The static method MyModule returns a configuration interface, and the parameter is the Imoduleconfigurations interface.
Now, in other modules, we can also configure the MyModule module that we have customized.
False"test";
In a sense, mymodule needs these configurations, you can inject mymoduleconfig and you can use these values.
Public classmyservice:itransientdependency{Private ReadOnlyMymoduleconfig _configuration; PublicMyService (mymoduleconfig configuration) {_configuration=configuration; } Public voidDoIt () {if(_configuration. SampleConfig2 = ="Test") { //... } }}
This means that in an ABP framework system, all modules can be centrally configured.
I hope that more domestic architects will be able to focus on the ABP project, and perhaps it will help you, perhaps with your participation, this project can develop better.
Welcome to add ABP Architecture Design Exchange QQ Group: 134710707
Click here to go to the ABP series articles General Catalogue
DDD-based Modern ASP.--ABP Series 5, ABP boot configuration