• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    C#
  • License
    GNU Lesser Genera...
  • Created about 13 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple feature configuration and availability-control for .NET. Please help me to improve the quality of NFeature by reporting issues here on GitHub.

NFeature

A simple feature configuration system (or feature toggle / flipper / whatever you want to call it.)

If you like NFeature, please let others know by sending a tweet (opens a form in a new window to send a tweet).

Feature configuration walls enable you to integrate your code earlier, which brings lots of goodness (such as helping to avoid branch merge problems.)

Example of use:

    if(Feature.MyCoolFeature.IsAvailable(manifest)) {
        //do some cool stuff
    }

If NFeature helps you or your team develop great software please let me know! It will help motivate me to develop and improve NFeature.

How to use:

-1. Check the target framework of your application

It must be .NET Framework 4 (not the Client Profile version - or you might get strange compilation errors.)

0. Get it

	nuget install nfeature

1. Define some features

In your code:

	
	public enum Feature {
		MyFeature,
		MyOtherFeature,
		MyOtherOtherFeature,
	}
		

In your configuration: (see also footnote 1)

NOTE: remember to replace Your.Feature.Type and Your.Feature.Type.Assembly in the text below.

	...
  	<configSections>
		...
		<!-- note that if you are using your own tenant enum then you will have 
		to replace "Your.Feature.Type, Your.Feature.Type.Assembly"
		with your type -->
		<section name="features" type="NFeature.Configuration.FeatureConfigurationSection`1[[Your.Feature.Type, Your.Feature.Type.Assembly]], NFeature.Configuration" />
		...
	</configSections>
	
	<features>
		<add name="MyFeature" state="Enabled" /> 
		<add name="MyOtherFeature" state="Previewable" /> <!-- will only be available to users who meet the feature-preview criteria -->
		<add name="MyOtherOtherFeature" state="Disabled" /> 
	</features>
	...
	

2. Define the availability-checking function

	//Here is a function that will only return 'true' if the feature is MyFeature.
	//Your function might be more elaborate. For example: feature availability might 
	//depend upon site load, user role or presence of a cookie.
	Func<FeatureSetting<Feature, DefaultTenantEnum>, EmptyArgs, bool> fn = (f, args) => f.Feature == Feature.MyFeature;

3. Take care of feature manifest initialization

For a working example of this see the integration test named FeatureEnumExtensionsTests in the NFeature.Test.Slow project, within the main solution.

	//NOTE: I suggest hiding this ugly initialization logic away in the IOC container configuration	
	var featureSettingRepo = new AppConfigFeatureSettingRepository<Feature>();
	var availabilityChecker = new FeatureSettingAvailabilityChecker<Feature>(fn); //from step 2
	var featureSettingService = new FeatureSettingService<Feature>(availabilityChecker, featureSettingRepo);
	var manifestCreationStrategy = new NFeature.DefaultImplementations.ManifestCreationStrategyDefault<Feature>(featureSettingRepo, featureSettingService); //we use the default for this example
	var featureManifestService = new FeatureManifestService<Feature>(manifestCreationStrategy);
	var featureManifest = featureManifestService.GetManifest();

4. Configure feature dependencies (if there are any)

	
    <features>
		<add name="MyFeature" dependencies="MyOtherFeature,MyOtherOtherFeature" />
	</features>

5. Add code that is conditional on feature availability

	//featureManifest ideally supplied via IOC container
	if(Feature.MyFeature.IsAvailable(featureManifest)) {
		//do some cool stuff
	}
	

6. Optionally configure feature-specific settings using Json (neatly side-stepping the need for angle brackets)

Arbitrary JSON is supported through the use of dynamic objects.

	
	<features>
		<add name="MyFeature" settings="{ mySetting:'mySettingValue', 
				   	                      myOtherSetting:['myOtherSettingValue','myOtherOtherSettingValue'] }" />
	</features>

7. Optionally specify dates for feature availability

	
    <features>
		<add name="MyFeature" startDtg="23/03/2012:00:00:00" /> <!-- available from 23rd March 2012 forever -->
		<add name="MyOtherFeature" startDtg="23/03/2012:00:00:00" endDtg="24/03/2012:00:00:00" /> <!-- available from 23rd March 2012 until the 24th -->
		<add name="MyOtherOtherFeature" endDtg="24/03/2012:00:00:00" /> <!-- available until 24th March 2012 -->
	</features>

8. At some future date... optionally mark your feature as Established to indicate that it is now integral to your application and cannot be turned off (see footnote 2)

Any availability checks for Established features will throw an exception, forcing their removal (as is good practice.)

	
	<features>
		<add name="MyFeature" state="Established" />
	</features>

9. ...

10. Profit!

How to build and/or run the tests:

  1. Run /build/build.bat
  2. Type in the desired option
  3. Hit return

Footnote 1: Please note that the logic to determine whether a feature is available is specified in the IFeatureManifestCreationStrategy instance you inject into the FeatureManifestService and (optionally, depending on your implementation of the aforementioned strategy) by the availability-checking function you inject into the FeatureSettingAvailabilityChecker.

Two concrete implementations of IFeatureManifestCreationStrategy are provided of-the-box: ManifestCreationStrategyDefault and ManifestCreationStrategyConsideringStateCookieTenantAndTime. A single default availability checker function is provided out of the box DefaultFunctions.AvailabilityCheckFunction, which may be used when the feature state, tenant, feature visibility mode and system time are known.

Footnote 2: Marking a feature as Established changes the behavior of the feature in the following way:

  • all dependencies must be Established
  • checking the feature's availability will throw an exception (because it is now always available by definition)

NOTE: this is pre-release quality software. There will be bugs/inaccuracies in the documentation. If you find an issue, please help me by adding an issue here on GitHub.

License & Copyright

This software is released under the GNU Lesser GPL. It is Copyright 2012, Ben Aston. I may be contacted at [email protected].

How to Contribute

Pull requests including bug fixes, new features and improved test coverage are welcomed. Please do your best, where possible, to follow the style of code found in the existing codebase.

Bitdeli Badge

More Repositories

1

NState

A state machine for .NET.
C#
45
star
2

NHelpfulException

A simple wrapper for System.Exception to help make exceptions more meaningful. Available on NuGet.
C#
5
star
3

GitCheatSheet

Yet another cheat sheet of git commands.
JavaScript
5
star
4

NPageObject

A simple UI test wrapper and DSL.
C#
5
star
5

BTree

Clone of BPlusDotNet
Java
5
star
6

mistic

JavaScript
4
star
7

NMap

A library to simplify the API for type creation and mapping.
C#
3
star
8

NFeature.Configuration

Configuration for NFeature.
C#
2
star
9

NDecorate

Enables composition of multi-functional types using the decorator pattern.
C#
2
star
10

invertebrate.js

A library for supporting client-side MVC development in JavaScript.
JavaScript
2
star
11

partial-application

JavaScript
2
star
12

NBasicExtensionMethod

A deliberately-small collection of useful extension methods. Available on NuGet.
C#
2
star
13

NOpenInterface

A small set of purposefully simple interfaces that are commonly required in .NET web applications.
C#
2
star
14

NBootstrap

A simple, flexible application bootstrapper. Available on NuGet.
C#
1
star
15

NServiceLocator

Simple ServiceLocator wrapper. Differs from the Microsoft offering by exposing binding in the common interface. Available on NuGet.
C#
1
star
16

NCacheFacade

A simple, flexible cache façade for .NET. This is a WIP and is not ready for use.
C#
1
star
17

taskr

Clustered task scheduler for .NET.
C#
1
star
18

event-api

JavaScript
1
star
19

interview-stuff

JavaScript
1
star
20

Workflow

1
star
21

NCacheFacade.Memcached

Memcached implementation of NCachedFacade.
1
star
22

NViewModelFactory

A library to simplify your MVC controllers using factory methods.
C#
1
star
23

NSure

Simple fluent assertions for .NET. Available on NuGet.
C#
1
star
24

try_git

1
star
25

XQuery

1
star
26

Bjma.Utility.Aop

Basic AOP types.
Shell
1
star
27

NCacheFacade.DataCache

1
star
28

qromisify

JavaScript
1
star
29

NServiceLocator.Ninject

NServiceLocator implementation for Ninject. Available on NuGet.
C#
1
star
30

Bjma.Utility.DataAccess

General data access types.
C#
1
star