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 / services.cs
Created May 7, 2019 15:49
Register multiple implementations - Method 01
services.AddScoped<IDiscountProcessor, OrderDiscountProcessor>();
services.AddScoped<IDiscount, SeasonalDiscount>();
services.AddScoped<IDiscount, LargeOrderDiscount>();
services.AddScoped<IDiscount, ThreeOrModeDiscount>();
services.TryAddEnumerable(ServiceDescriptor.Scoped<IThreeService, ThreeService>());
// or
services.TryAddEnumerable(new[] {
ServiceDescriptor.Scoped<IThreeService, ThreeService>(),
ServiceDescriptor.Scoped<IThreeService, AwesomeThreeService>(),
ServiceDescriptor.Scoped<IThreeService, SuperAwesomeThreeService>()
});
services.Replace(ServiceDescriptor.Scoped<IFourService, FourService>());
var fourService = ServiceDescriptor.Scoped<IFourService, FourService>();
services.Add(fourService);
var threeService = ServiceDescriptor.Scoped(typeof(IThreeService), typeof(ThreeService));
services.Add(threeService);
var twoService = ServiceDescriptor.Describe(typeof(ITwoService), typeof(TwoService), ServiceLifetime.Scoped);
services.Add(twoService);
var oneService = new ServiceDescriptor(typeof(IOneService), typeof(OneService), ServiceLifetime.Scoped);
services.Add(oneService);
@kasunkv
kasunkv / enable-resource-provider.sh
Last active March 10, 2019 16:40
Enable Azure Resource Provider using Azure CLI
# Login to Azure
az login --use-device-code
# Check the registration Status of the Resource Provider
az provider list --query "[?namespace == 'Microsoft.Compute']" --output table
# Register the Microsoft.Compute Resource Provider
az provider register --namespace "Microsoft.Compute"
@kasunkv
kasunkv / enable-resource-provider.ps1
Created March 10, 2019 16:35
Enable Azure Resource Provider using PowerShell
# Login to Azure Subscription
Login-AzureRmAccount
# Check the registration Status of the Resource Provider
Get-AzureRmResourceProvider -ListAvailable | Where-Object { $_.ProviderNamespace -eq "Microsoft.Compute" }
# Register the Microsoft.Compute Resource Provider
Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.Compute"
@kasunkv
kasunkv / create-policy.ps1
Last active March 10, 2019 07:38
Creating a Policy Assignment using Azure CLI
# Login to Azure
az login --use-device-code
# Get Regerence to Resource Group
$rgId = az group show --name "az-policy-rg" --query "id" --output tsv
# Get Reference to the Azure Policy Definition
$policyName = az policy definition list --query "[?displayName == 'Audit use of classic virtual machines'].name" --output tsv
# Assign the policy