Last active
December 13, 2015 20:19
-
-
Save CoreyKaylor/4969356 to your computer and use it in GitHub Desktop.
Feature toggle boilerplate
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
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!"))); | |
} | |
} | |
} |
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
public class FeatureSettings | |
{ | |
public bool SpecialFeatureEnabled { get; set; } | |
public bool SomeOtherFeatureEnabled { get; set; } | |
} |
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
public class FeatureToggleFubuRegistry : FubuRegistry | |
{ | |
public FeatureToggleFubuRegistry() | |
{ | |
Services(x => | |
{ | |
x.AddService(new ContentExtensionGraph()); | |
x.FillType<IActivator, FeaturesActivator>(); | |
}); | |
} | |
} |
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
@model FeatureToggleSample.SpecialFeatureModel | |
<div> | |
<h2>@Model.SpecialMessage</h2> | |
</div> |
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
public class SpecialFeatureEndpoint | |
{ | |
public SpecialFeatureModel get_feature(SpecialFeatureInput input) | |
{ | |
return new SpecialFeatureModel {SpecialMessage = "Feature Toggle On!"}; | |
} | |
} |
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
public class SpecialFeatureInput | |
{ | |
} |
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
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