简体   繁体   中英

Which design pattern Abp Framework (abp.io) are developers using?

At my company we are using the brand new Abp framework ( abp.io ). As it's a new framework, lots of documents are missing so we have to search at source code. Looking so much at the code I realized that's a pattern they're using that always appears Providers, ProvidersManagement, DefinitionProvider and so on . I would like to know if this pattern has a name or it's something just used there. I don't believe it's second option but I don't know.

Feature Module, Settings Module, Permission Modules are all module that are implemented using such design pattern.

Thank you guys!

I wanted to answer the question as the programmer behind these patterns in the ABP framework;

First of all, I want to explain why we are introducing these "provider" style pattern. The main reason is extensibility: A developer can extend the system by just implementing a provider interface and registering it to the framework. In this way, you don't need to replace or override a complete service to add a new behaviour.

For example, PermissionChecker service loops through the providers (those implement the IPermissionValueProvider interface) to allow you to decide if the current user has the requested permission. There are some pre-defined permission providers: user provider, role provider... etc. User provider checks if the current user has directly authorized for the permission while role provider checks if any role of the current user has the required permission. You can simply create a new provider implementation that checks the permission in a different way and allows the users to perform the related operation.

There are similar patterns used in the ASP.NET Core too.

For example, ASP.NET Core request localization middleware uses a similar pattern to determine the current culture for a web request. There are QueryStringRequestCultureProvider, CookieRequestCultureProvider... classes tries to determine the culture from different sources. It is also extensible, you can register new providers or re-order current providers.

We generally name such classes as "provider" or "contributor" in the framework.

Contributors are different classes those are participants of an operation. For example, for the menu system, there is a IMenuContributor interface that you can implement and take part while building the main menu in the application (add/remove/replace menu items).

The pattern is also similar to " Chain of Responsibility " pattern. For example, IPermissionValueProvider is similar to CoR pattern since each provider tries to check if the current user has permission for an operation. If the provider doesn't know that, the next provider is executed.

So, I don't know the exact name and I didn't 100% copied a pattern while implementing these. If this is a new pattern (I don't think so, but) I am not good at naming pattern, let's ask to Martin Fowler:)

BTW, we are constantly improving the documentation of the ABP Framework. In the previous milestone, we've completed most of the fundamental documents (like UOW, distributed event bus... etc). Recently, completely revised and extended the startup tutorial . Documentation will be a high priority in the next milestones too.

Thank you for using the ABP Framework:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM