Project plug-in development based on the components of the ABP module and the dependency injection component.

Source: Internet
Author: User

Project plug-in development based on the components of the ABP module and the dependency injection component.

Note: to read this article, you must first read the following two articles and have a certain foundation for dependency injection.

Module System:

Dependency injection:


I recently designed a project. Some of the business functions of this project need to be provided to this project as a plug-in to reduce coupling. The main project will not depend on specific business functions.

In the past, the simplest and most crude method was to scan all the dll files in the main program directory or the dll files in the specified directory, and then reflect and generate runtime objects.

Currently, dependency injection is used for the entire project, including plug-in projects.

Although it is often used for the development of projects, and occasionally read the relevant technical articles, but it is not known that there is a plug-in component.

I can't find a flexible and concise method to provide plug-in functions for the main program when I use dependency injection without knowing the components of the ABP plug-in.

Very worried, after some searches, found the Sample project in the official Github of the ABC: to know that there is this plug-in component.

With this plug-in component, it is much easier to develop plug-in projects.

I have also written a console Demo project based on the ABC. Let's take a look at it.

using System;using System.IO;using Abp;using Abp.PlugIns;namespace ConsoleApp{    public class Program    {        private static void Main(string[] args)        {            Console.WriteLine("Create AbpBootstrapper.");            using (var booter = AbpBootstrapper.Create<ConsoleAppModule>())            {                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PlugIns");                Console.WriteLine("path is " + path);                booter.PlugInSources.AddFolder(path);                Console.WriteLine("Added PlugIns Directory is completed.");                booter.Initialize();                Console.WriteLine("Initialize DI is completed.");                var test = booter.IocManager.Resolve<TestDI>();                test.Run();                var test2 = booter.IocManager.Resolve<TestDI>();                test2.Run();            }            Console.WriteLine("Dispose AbpBootstrapper.");            Console.ReadKey();        }    }}

Plug-in development:

1. In the main project, this code is required: booter. PlugInSources. AddFolder (path );

Notify the Module system and DI System of the ABP. The dll in this directory also needs to be scanned and initialized.

2. For each plug-in project, you need to add an AbpModule derived class.

Because only the Assembly containing the AbpModule derived class is scanned by the abcmodule, you need to create an AbpModule derived class to inform the abcmodule that scanning and initialization are also required here.

3. Each plug-in Interface/class must inherit Dependency interfaces of ISingletonDependency, ITransientDependency, and other Dependency interfaces located in the ABC. Dependency command space.

The ABP scans all interfaces/classes that inherit these interfaces, automatically solves dependencies for you, and creates related dependent objects.


A simple AbpModule derived class is as follows:

using System.Reflection;using Abp.Modules;namespace ConsoleApp.AsynStrategy{    public class ConsoleAppAsynStrategyModule : AbpModule    {        public override void Initialize()        {            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());        }    }}

Generally, every AbpModule derived class should use IocManager. RegisterAssemblyByConvention (Assembly. GetExecutingAssembly (); this code overrides the Initalize method.

Project Structure:

Directory structure:


Demo download:

Or Github:

Related Article

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: 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.