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
| var twoService = ServiceDescriptor.Describe(typeof(ITwoService), typeof(TwoService), ServiceLifetime.Scoped); | |
| services.Add(twoService); |
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
| var threeService = ServiceDescriptor.Scoped(typeof(IThreeService), typeof(ThreeService)); | |
| services.Add(threeService); |
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
| var fourService = ServiceDescriptor.Scoped<IFourService, FourService>(); | |
| services.Add(fourService); |
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.Replace(ServiceDescriptor.Scoped<IFourService, FourService>()); |
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.TryAddEnumerable(ServiceDescriptor.Scoped<IThreeService, ThreeService>()); | |
| // or | |
| services.TryAddEnumerable(new[] { | |
| ServiceDescriptor.Scoped<IThreeService, ThreeService>(), | |
| ServiceDescriptor.Scoped<IThreeService, AwesomeThreeService>(), | |
| ServiceDescriptor.Scoped<IThreeService, SuperAwesomeThreeService>() | |
| }); |
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<IDiscount, SeasonalDiscount>(); | |
| services.AddScoped<IDiscount, LargeOrderDiscount>(); | |
| services.AddScoped<IDiscount, ThreeOrModeDiscount>(); |
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>() | |
| }); |
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
| 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
| services.AddScoped<IDiscountProcessor, OrderDiscountProcessor>(); | |
| services.AddScoped<Discount>(sp => | |
| { | |
| return new DiscountBuilder() | |
| .WithMinimumBillAmount(1000) | |
| .WithMinimumItemCount(3) | |
| .WithPercentage(10) | |
| .Build(); | |
| }); |