DDD-based Modern ASP.--ABP Series 4, ABP module system

Source: Internet
Author: User

Click here to go to the ABP series articles General Catalogue

DDD-based Modern ASP.--ABP Series 4, ABP module system

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

Introduction to ABP Module systems

The ABP framework provides the basis for creating and assembling modules that can be relied upon by another module. In general, an assembly can be seen as a module. In the ABP framework, a module is defined by a class, and this class inherits from Abpmodule.

Translator Note: If you have learned orchard friends, you should know the module modules are powerful. The essence of the module is reusability, you can call it anywhere, and by implementing the module, the module you write can also be used by others.

Assembly Assembly: Assembly is a collection of information that contains the name, version number, self-description, file association, and file location of the program. The simplest thing to understand is that a DLL generated by your own class library can be seen as an assembly, which can include many classes, classes and many other methods.
. NET can get classes and methods in an assembly through reflection.


In the following example, we develop a mybolgapplication module that can be called in several different applications, with the following code:

 Public class // definition {    publicoverridevoid// Initialize     {        Iocmanager.registerassemblybyconvention (assembly.getexecutingassembly ());         // This line of code is basically the same. Its purpose is to register a specific class or interface of the current assembly into a dependency injection container.     }}

The ABP framework scans all the assemblies and discovers all the classes in the Abpmodule class that have already been imported, and if you have already created an app with multiple assemblies, our recommendation for ABP is to create a module for each assembly.


Life-Time Events

In one application, the ABP framework invokes some of the specified methods of module modules for starting and shutting down the module. We can overload these methods to accomplish our own task.

The ABP framework invokes these methods in the order of dependencies, assuming that module a relies on module B, then module B is initialized before module A, and the module starts with the following sequence of methods:

    1. Preinitialize-b
    2. Preinitialize-a
    3. Initialize-b
    4. Initialize-a
    5. Postinitialize-b
    6. Postinitialize-a

Here is a description of the specific method:


Preinitialize

Pre-initialization: This method is called the first time after the app is started. You can specify your own special code in this method before dependency injection registration. For example: If you create a traditional registration class, then you have to register the class (using Iocmanager to register the registration Class), you can register the event to the IOC container. such as

Initialize

Initialization: In this method is generally to carry out the registration of dependency injection, generally we iocmanager.registerassemblybyconvention this method to achieve. If you want to implement a custom dependency injection, then refer to the relevant documentation for dependency injection.

Postinitialize

Commit initialization: The last method used to parse a dependency.

Shutdown

Off: This method is called when the app is closed.

Module dependency (modules dependencies)

The ABP framework automatically resolves dependencies between modules, but we recommend that you explicitly declare dependencies by overloading the Getdependencies method.

[DependsOn (typeof(Myblogcoremodule))] // defining dependencies with annotations  Public class myblogapplicationmodule:abpmodule{    publicoverridevoid  Initialize ()    {        iocmanager.registerassemblybyconvention (assembly.getexecutingassembly ());}    }

For example, the above code, we declare the dependencies of Myblogapplicationmodule and Myblogcoremodule (through the property attribute), Myblogapplicationmodule This application module relies on the Myblogcoremodule core module, and the Myblogcoremodule core module is initialized before the Myblogapplicationmodule module.

How to customize the module approach

The modules we define ourselves may have methods that are called by other modules that depend on the current module, and the following example assumes that Module 2 relies on Module 1 and wants to invoke the method of Module 1 at pre-initialization time.

 Public classmymodule1:abpmodule{ Public Override voidInitialize ()//Initializing the module{iocmanager.registerassemblybyconvention (assembly.getexecutingassembly ());//here, a dependency injection is registered.     }     Public voidMyModuleMethod1 () {//Write a custom method here. }}[dependson (typeof(MyModule1))] Public classmymodule2:abpmodule{Private ReadOnlyMyModule1 _mymodule1;  PublicMyModule2 (MyModule1 myModule1) {_mymodule1=MyModule1; }     Public Override voidpreinitialize () {_mymodule1.mymodulemethod1 ();//call the MyModuleMethod1 method.     }     Public Override voidInitialize () {iocmanager.registerassemblybyconvention (assembly.getexecutingassembly ()); }}

In this way, the module 1 is injected into Module 2, so that Module 2 can call the method of Module 1.

Yangming Note:

ABP's modular system is similar to the Orchard module, but there are still big differences. The Orchard framework modifies the default load mode of the ASP (the module's DLL is not placed under the Bin folder and is placed under the Modules folder under the root folder of the Web project), enabling hot-swapping of the function modules. The module assembly of the ABP is also placed in the Bin folder, and no hot-swapping is implemented.

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 4, ABP module system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.