From 8467024d5411098d61e348150a9d2c3a312007a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 14 Aug 2020 14:33:15 +0300 Subject: [PATCH] refactor the global feature system --- .../Volo/Abp/GlobalFeatures/GlobalFeature.cs | 1 + .../Volo/Abp/GlobalFeatures/GlobalFeatureManager.cs | 3 +++ .../GlobalFeatureManagerModuleConfigurator.cs | 12 ++++++------ .../Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs | 2 ++ .../Volo/CmsKit/GlobalFeatures/CommentsFeature.cs | 2 +- ...CmsKitConfigurator.cs => GlobalCmsKitFeatures.cs} | 10 +++++----- .../Volo/CmsKit/GlobalFeatures/ReactionsFeature.cs | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) rename modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/{GlobalFeatureManagerCmsKitConfigurator.cs => GlobalCmsKitFeatures.cs} (72%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeature.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeature.cs index f0c113b1bf..11fb6961ed 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeature.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeature.cs @@ -10,6 +10,7 @@ namespace Volo.Abp.GlobalFeatures [NotNull] public GlobalFeatureManager FeatureManager { get; } + [NotNull] public string FeatureName { get; } public bool IsEnabled diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManager.cs index 7819f985de..80a5fcfae0 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManager.cs @@ -8,6 +8,9 @@ namespace Volo.Abp.GlobalFeatures { public static GlobalFeatureManager Instance { get; protected set; } = new GlobalFeatureManager(); + /// + /// A common dictionary to store arbitrary configurations. + /// [NotNull] public Dictionary Configuration { get; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManagerModuleConfigurator.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManagerModuleConfigurator.cs index 64692071e0..fc870da152 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManagerModuleConfigurator.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureManagerModuleConfigurator.cs @@ -5,16 +5,16 @@ namespace Volo.Abp.GlobalFeatures public abstract class GlobalModuleFeatures { [NotNull] - public GlobalFeatureConfiguratorDictionary AllFeatures { get; } + public GlobalFeatureManager FeatureManager { get; } [NotNull] - public GlobalFeatureManager FeatureManager { get; } + protected GlobalFeatureConfiguratorDictionary AllFeatures { get; } protected GlobalModuleFeatures( - GlobalFeatureManager featureManager) + [NotNull] GlobalFeatureManager featureManager) { + FeatureManager = Check.NotNull(featureManager, nameof(featureManager)); AllFeatures = new GlobalFeatureConfiguratorDictionary(); - FeatureManager = featureManager; } public virtual void EnableAll() @@ -43,10 +43,10 @@ namespace Volo.Abp.GlobalFeatures return AllFeatures[featureName]; } - protected TFeature GetFeature(string featureName) + protected TFeature GetFeature() where TFeature : GlobalFeature { - return (TFeature) AllFeatures[featureName]; + return (TFeature) GetFeature(GlobalFeatureNameAttribute.GetName()); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs index b5468096d3..295c8727e6 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalFeatureNameAttribute.cs @@ -8,6 +8,7 @@ namespace Volo.Abp.GlobalFeatures [AttributeUsage(AttributeTargets.Class)] public class GlobalFeatureNameAttribute : Attribute { + [NotNull] public string Name { get; } public GlobalFeatureNameAttribute([NotNull] string name) @@ -21,6 +22,7 @@ namespace Volo.Abp.GlobalFeatures return GetName(typeof(TFeature)); } + [NotNull] public static string GetName(Type type) { var attribute = type diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/CommentsFeature.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/CommentsFeature.cs index fb1c3fa9cb..c9615c51d4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/CommentsFeature.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/CommentsFeature.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.GlobalFeatures { public const string Name = "CmsKit.Comments"; - public CommentsFeature( + internal CommentsFeature( [NotNull] GlobalCmsKitFeatures cmsKit ) : base(cmsKit) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalFeatureManagerCmsKitConfigurator.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalCmsKitFeatures.cs similarity index 72% rename from modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalFeatureManagerCmsKitConfigurator.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalCmsKitFeatures.cs index 7fb1638e2d..dcdef4e8c2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalFeatureManagerCmsKitConfigurator.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/GlobalCmsKitFeatures.cs @@ -1,4 +1,5 @@ -using Volo.Abp.GlobalFeatures; +using JetBrains.Annotations; +using Volo.Abp.GlobalFeatures; namespace Volo.CmsKit.GlobalFeatures { @@ -6,11 +7,10 @@ namespace Volo.CmsKit.GlobalFeatures { public const string ModuleName = "CmsKit"; - public ReactionsFeature Reactions => GetFeature(ReactionsFeature.Name); + public ReactionsFeature Reactions => GetFeature(); + public CommentsFeature Comments => GetFeature(); - public CommentsFeature Comments => GetFeature(CommentsFeature.Name); - - public GlobalCmsKitFeatures(GlobalFeatureManager featureManager) + public GlobalCmsKitFeatures([NotNull] GlobalFeatureManager featureManager) : base(featureManager) { AddFeature(new ReactionsFeature(this)); diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/ReactionsFeature.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/ReactionsFeature.cs index 6c978e88e6..ad9a60b64d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/ReactionsFeature.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/GlobalFeatures/ReactionsFeature.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.GlobalFeatures { public const string Name = "CmsKit.Reactions"; - public ReactionsFeature( + internal ReactionsFeature( [NotNull] GlobalCmsKitFeatures cmsKit ) : base(cmsKit) {