ABP中特征

这篇博客的目的:1.了解ABP的特征这个模块,2.在AbpVue的模板中添加实时通讯的特征。

一、特性的定义。

1.关于特性,来自官方文档的解释:https://aspnetboilerplate.com/Pages/Documents/Feature-Management

在大多数SAAS系统中。都提供【版本】这个概念。不同的版本提供不同的功能特性。通过这种方式,一个SAAS系统可以提供不同的价格与功能组合给不同的租户。

ABP内置了特性(功能)模块以简化此类功能开发。您可以定义各种特性(功能),检测某个指定特性(功能)是否对某个指定租户开放,或者根据后台设置的特性(功能)开放对应的页面或是生成对应的导航。

Feature是什么?Feature就是对function的分类方法,其与function的关系就比如Role和User的关系一样。

ABP中Feature具有以下属性: 其中最重要的属性是name,用以表示feature的Identity,一个feature一个name. 一个Feature可以有一组子Features,从而构成Feature树。

2.值类型

系统已有两个基本的功能类型。

①. Boolean 功能

可以是true或者false。利用这个类型我们可以为租户启用(enable)或者禁用(disable)某些功能。

②. Value 功能

可以为任意值。我们可以用它来存储并者取得一个字符串,我们也可以很容易的用数字作为字符串来存储。

 

二、

第一步 在Core层的Features下的XXXFeatureProvider添加代码,作用是定义

            var sampleBooleanFeature = context.Create("SignalR", defaultValue: "true",
            inputType: new CheckboxInputType());
            sampleBooleanFeature.CreateChildFeature("SignalR.AspNetCore", defaultValue: "true", inputType: new CheckboxInputType());

第二步,修改应用层SessionsAppservice中的GetCurrentLoginInformations方法。

[DisableAuditing]
        public async Task<GetCurrentLoginInformationsOutput> GetCurrentLoginInformations()
        {
            var output = new GetCurrentLoginInformationsOutput
            {
                Application = new ApplicationInfoDto
                {
                    Version = AppVersionHelper.Version,
                    ReleaseDate = AppVersionHelper.ReleaseDate,
                    Features = new Dictionary<string, bool>()
                }
            };

            if (AbpSession.TenantId.HasValue)
            {
                output.Tenant = ObjectMapper.Map<TenantLoginInfoDto>(await GetCurrentTenantAsync());
                Dictionary<string, bool> dicFeatures = new Dictionary<string, bool>();
                var dicFeatureList = _iFeatureManager.GetAll();
                for (int i = 0; i < dicFeatureList.Count; i++)
                {
                    var feature = await _featureValueStore.GetValueOrNullAsync(AbpSession.TenantId.Value, dicFeatureList[i]);
                    if(feature!=null&&feature=="True")
                    {
                        dicFeatures.Add(dicFeatureList[i].Name, true);
                    }
                }
                output.Application.Features = dicFeatures;
            }

            if (AbpSession.UserId.HasValue)
            {
                output.User = ObjectMapper.Map<UserLoginInfoDto>(await GetCurrentUserAsync());
            }

            return output;
        }

第三部,在数据库中加入两个方法。

语句如图:


INSERT INTO [dbo].[AbpFeatures]
           ([CreationTime]
           ,[CreatorUserId]
           ,[Discriminator]
           ,[Name]
           ,[Value]
           ,[EditionId]
           ,[TenantId])
     VALUES
           (GETDATE()
           ,1
           ,'EditionFeatureSetting'
           ,'SignalR'
           ,'true'
           ,1
           ,1)
		   
		   INSERT INTO [dbo].[AbpFeatures]
           ([CreationTime]
           ,[CreatorUserId]
           ,[Discriminator]
           ,[Name]
           ,[Value]
           ,[EditionId]
           ,[TenantId])
     VALUES
           (GETDATE()
           ,1
           ,'EditionFeatureSetting'
           ,'AspNetCore'
           ,'true'
           ,1
           ,1)
GO

 

其余收获

1.IgnoreQueryFilters在查询中禁用全局过滤器,如逻辑删除等等。

相关参考:

官方文档:https://aspnetboilerplate.com/api-docs/html/N_Abp_Application_Features.htm

他人翻译:https://www.cnblogs.com/brucelee/p/9027151.html

源码解析:https://www.cnblogs.com/1zhk/p/5351968.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章