refactor the global feature system

pull/5062/head
Halil İbrahim Kalkan 5 years ago
parent 6a24a0de30
commit 8467024d54

@ -10,6 +10,7 @@ namespace Volo.Abp.GlobalFeatures
[NotNull] [NotNull]
public GlobalFeatureManager FeatureManager { get; } public GlobalFeatureManager FeatureManager { get; }
[NotNull]
public string FeatureName { get; } public string FeatureName { get; }
public bool IsEnabled public bool IsEnabled

@ -8,6 +8,9 @@ namespace Volo.Abp.GlobalFeatures
{ {
public static GlobalFeatureManager Instance { get; protected set; } = new GlobalFeatureManager(); public static GlobalFeatureManager Instance { get; protected set; } = new GlobalFeatureManager();
/// <summary>
/// A common dictionary to store arbitrary configurations.
/// </summary>
[NotNull] [NotNull]
public Dictionary<object, object> Configuration { get; } public Dictionary<object, object> Configuration { get; }

@ -5,16 +5,16 @@ namespace Volo.Abp.GlobalFeatures
public abstract class GlobalModuleFeatures public abstract class GlobalModuleFeatures
{ {
[NotNull] [NotNull]
public GlobalFeatureConfiguratorDictionary AllFeatures { get; } public GlobalFeatureManager FeatureManager { get; }
[NotNull] [NotNull]
public GlobalFeatureManager FeatureManager { get; } protected GlobalFeatureConfiguratorDictionary AllFeatures { get; }
protected GlobalModuleFeatures( protected GlobalModuleFeatures(
GlobalFeatureManager featureManager) [NotNull] GlobalFeatureManager featureManager)
{ {
FeatureManager = Check.NotNull(featureManager, nameof(featureManager));
AllFeatures = new GlobalFeatureConfiguratorDictionary(); AllFeatures = new GlobalFeatureConfiguratorDictionary();
FeatureManager = featureManager;
} }
public virtual void EnableAll() public virtual void EnableAll()
@ -43,10 +43,10 @@ namespace Volo.Abp.GlobalFeatures
return AllFeatures[featureName]; return AllFeatures[featureName];
} }
protected TFeature GetFeature<TFeature>(string featureName) protected TFeature GetFeature<TFeature>()
where TFeature : GlobalFeature where TFeature : GlobalFeature
{ {
return (TFeature) AllFeatures[featureName]; return (TFeature) GetFeature(GlobalFeatureNameAttribute.GetName<TFeature>());
} }
} }
} }

@ -8,6 +8,7 @@ namespace Volo.Abp.GlobalFeatures
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class GlobalFeatureNameAttribute : Attribute public class GlobalFeatureNameAttribute : Attribute
{ {
[NotNull]
public string Name { get; } public string Name { get; }
public GlobalFeatureNameAttribute([NotNull] string name) public GlobalFeatureNameAttribute([NotNull] string name)
@ -21,6 +22,7 @@ namespace Volo.Abp.GlobalFeatures
return GetName(typeof(TFeature)); return GetName(typeof(TFeature));
} }
[NotNull]
public static string GetName(Type type) public static string GetName(Type type)
{ {
var attribute = type var attribute = type

@ -8,7 +8,7 @@ namespace Volo.CmsKit.GlobalFeatures
{ {
public const string Name = "CmsKit.Comments"; public const string Name = "CmsKit.Comments";
public CommentsFeature( internal CommentsFeature(
[NotNull] GlobalCmsKitFeatures cmsKit [NotNull] GlobalCmsKitFeatures cmsKit
) : base(cmsKit) ) : base(cmsKit)
{ {

@ -1,4 +1,5 @@
using Volo.Abp.GlobalFeatures; using JetBrains.Annotations;
using Volo.Abp.GlobalFeatures;
namespace Volo.CmsKit.GlobalFeatures namespace Volo.CmsKit.GlobalFeatures
{ {
@ -6,11 +7,10 @@ namespace Volo.CmsKit.GlobalFeatures
{ {
public const string ModuleName = "CmsKit"; public const string ModuleName = "CmsKit";
public ReactionsFeature Reactions => GetFeature<ReactionsFeature>(ReactionsFeature.Name); public ReactionsFeature Reactions => GetFeature<ReactionsFeature>();
public CommentsFeature Comments => GetFeature<CommentsFeature>();
public CommentsFeature Comments => GetFeature<CommentsFeature>(CommentsFeature.Name); public GlobalCmsKitFeatures([NotNull] GlobalFeatureManager featureManager)
public GlobalCmsKitFeatures(GlobalFeatureManager featureManager)
: base(featureManager) : base(featureManager)
{ {
AddFeature(new ReactionsFeature(this)); AddFeature(new ReactionsFeature(this));

@ -8,7 +8,7 @@ namespace Volo.CmsKit.GlobalFeatures
{ {
public const string Name = "CmsKit.Reactions"; public const string Name = "CmsKit.Reactions";
public ReactionsFeature( internal ReactionsFeature(
[NotNull] GlobalCmsKitFeatures cmsKit [NotNull] GlobalCmsKitFeatures cmsKit
) : base(cmsKit) ) : base(cmsKit)
{ {

Loading…
Cancel
Save