Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Feature toggle boilerplate
public class FeaturesActivator : IActivator
{
private readonly FeatureSettings _featureSettings;
private readonly ContentExtensionGraph _extensionGraph;
public FeaturesActivator(FeatureSettings featureSettings, ContentExtensionGraph extensionGraph)
{
_featureSettings = featureSettings;
_extensionGraph = extensionGraph;
}
public void Activate(IEnumerable<IPackageInfo> packages, IPackageLog log)
{
if (_featureSettings.SpecialFeatureEnabled)
{
_extensionGraph.Register("feature-area", new LambdaExtension<HomeModel>(page => page.Partial<SpecialFeatureInput>()));
}
if (_featureSettings.SomeOtherFeatureEnabled)
{
_extensionGraph.Register("feature-area", new LambdaExtension<HomeModel>(page => new HtmlTag("h3").Text("HtmlTag Toggle On!")));
}
}
}
public class FeatureSettings
{
public bool SpecialFeatureEnabled { get; set; }
public bool SomeOtherFeatureEnabled { get; set; }
}
public class FeatureToggleFubuRegistry : FubuRegistry
{
public FeatureToggleFubuRegistry()
{
Services(x =>
{
x.AddService(new ContentExtensionGraph());
x.FillType<IActivator, FeaturesActivator>();
});
}
}
@model FeatureToggleSample.SpecialFeatureModel
<div>
<h2>@Model.SpecialMessage</h2>
</div>
public class SpecialFeatureEndpoint
{
public SpecialFeatureModel get_feature(SpecialFeatureInput input)
{
return new SpecialFeatureModel {SpecialMessage = "Feature Toggle On!"};
}
}
public class SpecialFeatureInput
{
}
public class SpecialFeatureModel
{
public string SpecialMessage { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment