AbpKernelModule, abpmodule

Source: Internet
Author: User

AbpKernelModule, abpmodule
PreInitialize IocManager. AddConventionalRegistrar (new BasicConventionalRegistrar ());

Add BasicConventionRegister. Here, we only add this basic registration method, which is a bit difficult to translate. It mainly tells Ioc to pay attention to three types during subsequent registration.

ITransientDependency

ISingletonDependency

IInterceptor

This means that if you add any of the above interfaces to the defined class, it will be automatically registered to Ioc by the Abp framework,

However, here we only tell Ioc that there is such a registration method, and the real registration is not here.

 

ValidationInterceptorRegistrar. Initialize (IocManager );
internal static class ValidationInterceptorRegistrar{    public static void Initialize(IIocManager iocManager)    {        iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered;    }    private static void Kernel_ComponentRegistered(string key, IHandler handler)    {        if (typeof(IApplicationService).IsAssignableFrom(handler.ComponentModel.Implementation))        {            handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(ValidationInterceptor)));        }    }}

This code is very interesting. It means that when a component in Ioc is registered (that is, when a type is added to Ioc ), check whether the object is an IApplicationService (that is, only the ApplicationService layer is verified). If yes, implement the Validation interception. After the interception, the method parameters at the ApplicationService layer can be checked, interceptors is a collection of Interceptors that can be added to more Interceptors. For example, you can call the method to call the cross-plane operations of log monitoring.

So when a request enters the ApplicationService layer, the first thing to do is Validation.

Skip the Validation condition:
  

DisableValidationAttribute, which can only be added to a method

Non-Public Method

The parameter is null.

If the verification fails, an AbpValidationException is thrown with the detailed fields and error information of the verification failure.

Finally, if the IShouldNormalize interface is added to a property definition in the parameter, the Normalize method of IShouldNormalize will be called to perform data normalization operations. I haven't figured out how to use it yet.

 

FeatureInterceptorRegistrar. Initialize (IocManager );

It targets all the objects in Ioc. the interceptor intercepts two elements:

  

A. The class has RequiresFeatureAttribute.

B. A method in the class has RequiresFeatureAttribute.

This looks like a general functional check, which should exist for a small extension function. It is not used yet and is ignored for the moment.

 

AuditingInterceptorRegistrar. Initialize (IocManager );

The audit interceptor is a very useful data interception. Its main function is to record the data of intercepted method calls.

Interception rules:

private static bool ShouldIntercept(Type type){    if (_auditingConfiguration.Selectors.Any(selector => selector.Predicate(type)))    {        return true;    }    if (type.IsDefined(typeof(AuditedAttribute), true)) //TODO: true or false?    {        return true;    }    if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true))) //TODO: true or false?    {        return true;    }    return false;}

We can see that except the first extension rule, the other two are processed through AuditedAttribute.

About Selectors selector, we can see the following code:

Public static void Initialize (IIocManager iocManager) {_ auditingConfiguration = iocManager. Resolve <IAuditingConfiguration> (); if (! _ AuditingConfiguration. IsEnabled) {return;} iocManager. IocContainer. Kernel. ComponentRegistered + = Kernel_ComponentRegistered ;}

Write _ auditingConfiguration. IsEnable to determine whether to enable it, but this method itself is executed in AbpKernel. Where can I set this value?

Through the analysis of the application lifecycle in the previous article,

protected virtual void Application_Start(object sender, EventArgs e){    AbpBootstrapper.IocManager.RegisterIfNot<IAssemblyFinder, WebAssemblyFinder>();    AbpBootstrapper.Initialize();}

However, the registration of IAuditingConfiguration and the Init of this method are all in the Initizlize method. If you are using non-Abp source code, it seems that there is no way to close it, therefore, the answer to the default Auditing function is no, which will be processed by the author later (this has been linked to the author: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/721 ).

Saving audit logs:

Configuration. settings. providers. add <EmailSettingProvider> (); Configuration. unitOfWork. registerFilter (AbpDataFilters. softDelete, true); Configuration. unitOfWork. registerFilter (AbpDataFilters. mustHaveTenant, true); Configuration. unitOfWork. registerFilter (AbpDataFilters. mayHaveTenant, true); ConfigureCaches ();

EmailSetting email settings

SoftDelete: Soft Delete settings

MustHaveTenant: Multi-tenant settings

MayHaveTenant:

Caches: Cache Policy Settings

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