Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of ASP.NET Core Zero Module system

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of ASP.NET Core Zero module system", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and study the "sample analysis of ASP.NET Core Zero module system" this article.

Brief introduction

In ABP, the definition of a template is a class that only needs to inherit AbpModule, which can be searched for ABP installation through the nuget package.

The following shows how to define a module in an application or class library:

Public class ApplicationModule: AbpModule {public override void Initialize () {IocManager.RegisterAssemblyByConvention (typeof (ApplicationModule) .GetAssembly ();}}

Description: the role of IocManager.RegisterAssemblyByConvention is to register the current assembly module with the container. As a module, it is common to expose the corresponding services of the module.

All of these services are declared according to the declaration cycle, such as ITransientDependency, ISingletonDependency.

Some of the details of the IocManager.RegisterAssemblyByConvention implementation are shown below:

Public void RegisterAssembly (IConventionalRegistrationContext context) {/ / Transient context.IocManager.IocContainer.Register (Classes.FromAssembly (context.Assembly) .IncludeNonPublicTypes () .BasedOn () .if (type = >! type.GetTypeInfo () .IsGenericTypeDefinition) .WithService.self () .WithService.DefaultInterfaces () .LifestyleTransient () / / Singleton context.IocManager.IocContainer.Register (Classes.FromAssembly (context.Assembly) .IncludeNonPublicTypes () .BasedOn () .if (type = >! type.GetTypeInfo () .IsGenericTypeDefinition) .WithService.self () .WithService.DefaultInterfaces () .LifestyleSingleton () / /.} common methods

In AbpModule, several sets of methods are defined before and after the application module is loaded, as follows:

Public virtual void Initialize (); public virtual void PostInitialize (); public virtual void PreInitialize (); public virtual void Shutdown ()

Initialize: typically, this is used to register assembly dependency options

PostInitialize: initialize the last call

PreInitialize: called before initialization

Shutdown: called when the application is closed

Module dependence

Generally speaking, a module often depends on one or more modules, which also involves the loading life cycle of the module.

Suppose that module A depends on module B, which means that module B will initialize before module A.

With regard to the dependencies between modules, you can display the declaration for the module by DependsOn as a feature, as follows:

[DependsOn (typeof (BModule))] public class AModule: AbpModule {public override void Initialize () {/ /...}} module load

It is common for any module to rely on the boot module to load, such as each module in the chassis: memory, hard disk, video card, power supply. All need the power-up process, let them carry out the whole start-up process.

Abp relies on AbpBootstrapper for call initialization and can be loaded through the Initialize method.

Public static class ApplicationBootstrapper {public static AbpBootstrapper AbpBootstrapper {get; private set;} public static void Init () {/ /... AbpBootstrapper.Initialize ();}}

Similarly, the module can also load the module by reading the specified folder path, as follows:

Services.AddAbp (options = > {options.PlugInSources.Add (new FolderPlugInSource (@ "C:\ MyPlugIns"));}); orservices.AddAbp (options = > {options.PlugInSources.AddFolder (@ "C:\ MyPlugIns");}); above is all the content of the article "sample Analysis of ASP.NET Core Zero Module system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report