Created
June 11, 2013 15:19
-
-
Save rarous/5757736 to your computer and use it in GitHub Desktop.
Feature toggles support in Windsor container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using Castle.MicroKernel; | |
using Castle.MicroKernel.Registration; | |
namespace Project.Installers { | |
public static class FeatureToggles { | |
static readonly string[] OnStates = { "on", "enabled" }; | |
static readonly IRegistration FeatureOff = new SkipRegistration(); | |
public static IRegistration FeatureToggle(this IRegistration feature, Parameter toggle) { | |
if (IsEnabled(toggle.Value)) | |
return feature; | |
return FeatureOff; | |
} | |
public static Predicate<Type> IsEnabled(Parameter toggle) { | |
if (IsEnabled(toggle.Value)) | |
return _ => true; | |
return _ => false; | |
} | |
static bool IsEnabled(string value) { | |
return value == null || OnStates.Contains(value.Trim().ToLowerInvariant()); | |
} | |
} | |
class SkipRegistration : IRegistration { | |
public void Register(IKernelInternal kernel) { } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Component. | |
For<IService>(). | |
ImplementedBy<Service>(). | |
FeatureToggle(Dependency.OnAppSettingsValue("FeatureToggle")), | |
Classes. | |
FromAssemblyInDirectory(new AssemblyFilter(".")). | |
BasedOn<ServiceBase>(). | |
If(FeatureToggles.IsEnabled(Dependency.OnAppSettingsValue("FeatureToggle"))). | |
WithServiceBase(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment