Skip to content

Instantly share code, notes, and snippets.

View kasunkv's full-sized avatar
💭
I may be slow to respond.

Kasun Kodagoda kasunkv

💭
I may be slow to respond.
View GitHub Profile
@kasunkv
kasunkv / RequirementType.cs
Created January 18, 2020 16:16
RequirementType enum
namespace Microsoft.FeatureManagement
{
public enum RequirementType
{
Any = 0, // The enabled state will be attained if any feature in the set is enabled.
All = 1 // The enabled state will be attained if all features in the set are enabled.
}
}
@kasunkv
kasunkv / HomeController.cs
Created January 16, 2020 16:06
Using IFeatureManager to access feature flags
using Microsoft.FeatureManagement.Mvc;
namespace MusicStore.Web.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IAlbumService _albumService;
private readonly IFeatureManager _featureManager;
@kasunkv
kasunkv / Index.cshtml
Created January 16, 2020 15:59
Using feature tag helper to wrap UI elements to hide behind feature flags
@model HomeViewModel
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<feature name="@Features.PromotionDiscounts" negate="true"><h1 class="display-4">Enjoy the latest music from your favorite artist</h1></feature>
<feature name="@Features.PromotionDiscounts"><h1 class="display-4">Enjoy 25% off for selected albums from your favorite artist</h1></feature>
...
@kasunkv
kasunkv / _ViewImports.cshtml
Created January 16, 2020 15:19
Adding tag helper to the _ViewImports.cshtml
@addTagHelper *, Microsoft.FeatureManagement.AspNetCore
@kasunkv
kasunkv / Features.cs
Created January 16, 2020 15:15
String constants with feature names
namespace MusicStore.Shared.FeatureManagement
{
public static class Features
{
public const string Promotions = "Promotion";
public const string PromotionDiscounts = "Promotion.Discounts";
public const string UserSuggestions = "Suggestion.User";
}
}
@kasunkv
kasunkv / HomeController.cs
Created January 16, 2020 15:05
Blocking access to Controller Action methods using FeatureGate action filter.
using Microsoft.FeatureManagement.Mvc;
namespace MusicStore.Web.Controllers
{
public class HomeController : Controller
{
...
[FeatureGate(Features.Promotions)]
public async Task<IActionResult> Promotions()
@kasunkv
kasunkv / appsettings.json
Created January 16, 2020 14:50
Defining feature flags in appsettings.json
{
...
"FeatureManagement": {
"Promotion": false,
"Promotion.Discounts": false,
"Suggestion.User": false
}
}
@kasunkv
kasunkv / Startup.cs
Created January 16, 2020 14:20
Add Feature Management services into DI
using Microsoft.FeatureManagement;
namespace MusicStore.Web
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
...
@kasunkv
kasunkv / Program.cs
Created October 1, 2019 15:09
Using Azure App Configuration in ASP.Net Core MVC Application
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost
.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var settings = config.Build();
// Connect to Azure App Configuration using the Connection String.
config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfiguration"]);
})
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, config) => {
// Fetch app settings from Azure Key Vault if its in production mode.
if (ctx.HostingEnvironment.IsProduction())
{
var configRoot = config.Build();
var tokenProvider = new AzureServiceTokenProvider();