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
{ | |
"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" |
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
namespace Function.DependencyInjection.Timer | |
{ | |
public class TimeFunction | |
{ | |
private readonly IHelloService _helloService; | |
public TimeFunction(IHelloService helloService) | |
{ | |
_helloService = helloService; | |
} |
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
[assembly: FunctionsStartup(typeof(Startup))] | |
namespace Function.DependencyInjection.Timer | |
{ | |
public class Startup : FunctionsStartup | |
{ | |
public override void Configure(IFunctionsHostBuilder builder) | |
{ | |
builder.Services.AddScoped<IHelloService, HelloService>(); | |
} | |
} |
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
// Creating the Key Vault client | |
var tokenProvider = new AzureServiceTokenProvider(); | |
var vaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback)); |
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 async Task<IActionResult> Index() | |
{ | |
var vaultName = _configuration["AppSettings:KeyVaultName"]; | |
var secretName = _configuration["AppSettings:SecretName"]; | |
var vm = new HomeViewModel(); | |
try | |
{ | |
// Creating the Key Vault client |
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 OrderDiscountProcessor : IDiscountProcessor | |
{ | |
private readonly Discount _discount; | |
public OrderDiscountProcessor(Discount discount) | |
{ | |
_discount = discount; | |
} | |
public double ProcessDiscount(OrderViewModel order) |
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
services.AddScoped<IDiscountProcessor, OrderDiscountProcessor>(); | |
services.AddScoped<Discount>(sp => | |
{ | |
return new DiscountBuilder() | |
.WithMinimumBillAmount(1000) | |
.WithMinimumItemCount(3) | |
.WithPercentage(10) | |
.Build(); | |
}); |
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 (double, List<string>) ProcessDiscount(OrderViewModel order) | |
{ | |
var discountDiscroptoons = new List<string>(); | |
var totalDiscount = 0.0; | |
foreach (var discount in _discounts) | |
{ | |
var addedDiscount = discount.CalculateDiscount(order); | |
if (addedDiscount > 0) | |
{ |
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 OrderDiscountProcessor : IDiscountProcessor | |
{ | |
private readonly IEnumerable<IDiscount> _discounts; | |
public OrderDiscountProcessor(IEnumerable<IDiscount> discounts) | |
{ | |
_discounts = discounts; | |
} | |
// ... | |
} |
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
services.AddScoped<IDiscountProcessor, OrderDiscountProcessor>(); | |
services.TryAddEnumerable(new[] | |
{ | |
ServiceDescriptor.Scoped<IDiscount, SeasonalDiscount>(), | |
ServiceDescriptor.Scoped<IDiscount, LargeOrderDiscount>(), | |
ServiceDescriptor.Scoped<IDiscount, ThreeOrModeDiscount>() | |
}); |