简体   繁体   English

开发人员使用哪种设计模式 Abp 框架 (abp.io)?

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

At my company we are using the brand new Abp framework ( abp.io ).在我公司,我们使用全新的 Abp 框架( 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 .看了这么多代码,我意识到这是他们使用的一种模式,总是出现Providers、ProvidersManagement、DefinitionProvider 等等 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;作为 ABP 框架中这些模式背后的程序员,我想回答这个问题;

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.例如, PermissionChecker服务循环通过提供者(实现 IPermissionValueProvider 接口的提供者)以允许您确定当前用户是否具有请求的权限。 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. ASP.NET 内核中也使用了类似的模式。

For example, ASP.NET Core request localization middleware uses a similar pattern to determine the current culture for a web request.例如,ASP.NET 核心请求本地化中间件使用类似的模式来确定 web 请求的当前区域性。 There are QueryStringRequestCultureProvider, CookieRequestCultureProvider... classes tries to determine the culture from different sources.有 QueryStringRequestCultureProvider、CookieRequestCultureProvider... 类试图确定来自不同来源的文化。 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).例如,对于菜单系统,有一个 IMenuContributor 接口,您可以在构建应用程序的主菜单时实现和参与(添加/删除/替换菜单项)。

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.例如,IPermissionValueProvider 类似于 CoR 模式,因为每个提供者都会尝试检查当前用户是否具有操作权限。 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.所以,我不知道确切的名称,并且在实现这些时我没有 100% 复制模式。 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:)如果这是一个新模式(我不这么认为,但是)我不擅长命名模式,让我们问问 Martin Fowler:)

BTW, we are constantly improving the documentation of the ABP Framework.顺便说一句,我们正在不断改进 ABP 框架的文档。 In the previous milestone, we've completed most of the fundamental documents (like UOW, distributed event bus... etc).在上一个里程碑中,我们已经完成了大部分基础文档(如 UOW、分布式事件总线......等)。 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:)感谢您使用 ABP 框架:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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