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 / OrderDiscountProcessor.cs
Created May 12, 2019 14:14
Implementation of IDiscountProcessor.cs
public class OrderDiscountProcessor : IDiscountProcessor
{
private readonly Discount _discount;
public OrderDiscountProcessor(Discount discount)
{
_discount = discount;
}
public double ProcessDiscount(OrderViewModel order)
@kasunkv
kasunkv / HomeContraoller.cs
Last active June 8, 2019 09:06
Using AzureServiceTokenProvider to fetch the Access Token for Key Vault
public async Task<IActionResult> Index()
{
var vaultName = _configuration["AppSettings:KeyVaultName"];
var secretName = _configuration["AppSettings:SecretName"];
var vm = new HomeViewModel();
try
{
// Creating the Key Vault client
@kasunkv
kasunkv / HomeContraoller.cs
Created June 8, 2019 09:13
AzureServiceTokenProvicer callback
// Creating the Key Vault client
var tokenProvider = new AzureServiceTokenProvider();
var vaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback));
@kasunkv
kasunkv / Startup.cs
Created June 9, 2019 11:39
Azure Functions V2 Startup Class
[assembly: FunctionsStartup(typeof(Startup))]
namespace Function.DependencyInjection.Timer
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddScoped<IHelloService, HelloService>();
}
}
@kasunkv
kasunkv / TimeFunction.cs
Created June 9, 2019 11:44
Construction Injecting the Dependencies in to Azure Function.
namespace Function.DependencyInjection.Timer
{
public class TimeFunction
{
private readonly IHelloService _helloService;
public TimeFunction(IHelloService helloService)
{
_helloService = helloService;
}
{
"AppSettings": {
"KeyVaultName": "gabc-vault",
"HomePage": {
"Title": "Hello From Local App Settings",
"Description": "This description is taken from the appSettings.json."
},
"ExternalService": {
"ClientId": "client-localhost",
"ApiKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
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();
@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"]);
})
@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 / appsettings.json
Created January 16, 2020 14:50
Defining feature flags in appsettings.json
{
...
"FeatureManagement": {
"Promotion": false,
"Promotion.Discounts": false,
"Suggestion.User": false
}
}