Skip to content

FeatureFlagManager

Ershad Raoufi- ارشاد رئوفی edited this page Apr 11, 2023 · 4 revisions

The FeatureFlagManager class is a part of the FeatureFlag.Core namespace and is designed to manage feature flags in a .NET application. It implements the IFeatureFlagManager interface, which defines the methods for checking if a feature flag is active and retrieving information about a feature flag.

Constructor:

•FeatureFlagManager(string path, IJsonConvertor jsonConvertor): This constructor takes two parameters: path and jsonConvertor. path is the path to the JSON file that contains the feature flag configuration, and jsonConvertor is an instance of the IJsonConvertor interface used for parsing the JSON file and converting it into a list of FeatureFagItem objects.

Methods:

•IsActiveFeatureWithName(string nameOfFeature): This method checks if a feature flag with the specified name is active. It first looks for the FeatureFagItem object that matches the nameOfFeature parameter in the list of _featureFagItems, which contains the feature flag configuration. If the feature flag is found and it is enabled (i.e., Enabled property is set to true), it performs custom attribute validation by calling the CustomAttributeValidation() method. If the custom attribute validation returns true, then it returns true, indicating that the feature flag is active.

•CustomAttributeValidation(FeatureFagItem input): This is a virtual method that can be overridden in derived classes to provide custom validation logic for feature flags. By default, it always returns true, but you can override it to implement your own validation logic.

•GetFeatureFlagInfoWithName(string nameOfFeature): This method retrieves the FeatureFagItem object that corresponds to the feature flag with the specified name. It first looks for the FeatureFagItem object that matches the nameOfFeature parameter in the list of _featureFagItems. If the feature flag is found, it returns the FeatureFagItem object, which contains information about the feature flag, such as its name, description, and enabled status.

Interfaces: •IFeatureFlagManager: This is an interface that defines the methods for managing feature flags. It includes the IsActiveFeatureWithName(string nameOfFeature) and GetFeatureFlagInfoWithName(string nameOfFeature) methods, which are implemented by the FeatureFlagManager class. Implementing this interface allows for easy integration of custom feature flag management logic into your application.

Other Classes:

•FeatureFagItem: This is a model class that represents a feature flag item. It contains properties such as Name (the name of the feature flag), Description (a description of the feature flag), Enabled (a boolean indicating if the feature flag is enabled), and other custom attributes that can be used for validation or other purposes.

•IJsonConvertor: This is an interface that defines the contract for converting JSON data into objects. It is used by the FeatureFlagManager class to parse the JSON file and convert it into a list of FeatureFagItem objects. You can implement this interface in your own class to provide custom JSON parsing logic, allowing you to use different JSON libraries or data sources for your feature flag configuration.

Clone this wiki locally