From 84203537edfb067d3746c0dcfea0cf467e7aa483 Mon Sep 17 00:00:00 2001 From: Enrico Tirotta <33745977+EnricoTirotta@users.noreply.github.com> Date: Sat, 20 Jan 2018 11:10:03 +0100 Subject: [PATCH 1/4] Update MediatorModule.cs --- .../Infrastructure/AutofacModules/MediatorModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs index 83c2b1ba2..d0dce865f 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs @@ -19,11 +19,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly) .AsImplementedInterfaces(); - // Register all the Command classes (they implement IAsyncRequestHandler) in assembly holding the Commands + // Register all the Command classes (they implement IRequestHandler) in assembly holding the Commands builder.RegisterAssemblyTypes(typeof(CreateOrderCommand).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(IRequestHandler<,>)); - // Register the DomainEventHandler classes (they implement IAsyncNotificationHandler<>) in assembly holding the Domain Events + // Register the DomainEventHandler classes (they implement INotificationHandler<>) in assembly holding the Domain Events builder.RegisterAssemblyTypes(typeof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler).GetTypeInfo().Assembly) .AsClosedTypesOf(typeof(INotificationHandler<>)); From 2451ab9dff4029c461327817c11bac006a231c63 Mon Sep 17 00:00:00 2001 From: Robert Raboud Date: Tue, 30 Jan 2018 08:16:20 -0500 Subject: [PATCH 2/4] Changed AddRange to AddRangeAwait --- .../Catalog.API/Infrastructure/CatalogContextSeed.cs | 6 +++--- .../Identity/Identity.API/Data/ApplicationDbContextSeed.cs | 2 +- .../Identity.API/Data/ConfigurationDbContextSeed.cs | 6 +++--- .../Marketing.API/Infrastructure/MarketingContextSeed.cs | 2 +- .../Ordering.API/Infrastructure/OrderingContextSeed.cs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs index 42ac7b740..712719e23 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs @@ -30,7 +30,7 @@ if (!context.CatalogBrands.Any()) { - context.CatalogBrands.AddRange(useCustomizationData + await context.CatalogBrands.AddRangeAsync(useCustomizationData ? GetCatalogBrandsFromFile(contentRootPath, logger) : GetPreconfiguredCatalogBrands()); @@ -39,7 +39,7 @@ if (!context.CatalogTypes.Any()) { - context.CatalogTypes.AddRange(useCustomizationData + await context.CatalogTypes.AddRangeAsync(useCustomizationData ? GetCatalogTypesFromFile(contentRootPath, logger) : GetPreconfiguredCatalogTypes()); @@ -48,7 +48,7 @@ if (!context.CatalogItems.Any()) { - context.CatalogItems.AddRange(useCustomizationData + await context.CatalogItems.AddRangeAsync(useCustomizationData ? GetCatalogItemsFromFile(contentRootPath, context, logger) : GetPreconfiguredItems()); diff --git a/src/Services/Identity/Identity.API/Data/ApplicationDbContextSeed.cs b/src/Services/Identity/Identity.API/Data/ApplicationDbContextSeed.cs index 3dbf28171..058c58dbc 100644 --- a/src/Services/Identity/Identity.API/Data/ApplicationDbContextSeed.cs +++ b/src/Services/Identity/Identity.API/Data/ApplicationDbContextSeed.cs @@ -33,7 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data if (!context.Users.Any()) { - context.Users.AddRange(useCustomizationData + await context.Users.AddRangeAsync(useCustomizationData ? GetUsersFromFile(contentRootPath, logger) : GetDefaultUser()); diff --git a/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs b/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs index b109bf896..db43c6019 100644 --- a/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs +++ b/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs @@ -27,17 +27,17 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data if (!await context.Clients.AnyAsync()) { - context.Clients.AddRange(Config.GetClients(clientUrls).Select(client => client.ToEntity())); + await context.Clients.AddRangeAsync(Config.GetClients(clientUrls).Select(client => client.ToEntity())); } if (!await context.IdentityResources.AnyAsync()) { - context.IdentityResources.AddRange(Config.GetResources().Select(resource => resource.ToEntity())); + await context.IdentityResources.AddRangeAsync(Config.GetResources().Select(resource => resource.ToEntity())); } if (!await context.ApiResources.AnyAsync()) { - context.ApiResources.AddRange(Config.GetApis().Select(api => api.ToEntity())); + await context.ApiResources.AddRangeAsync(Config.GetApis().Select(api => api.ToEntity())); } await context.SaveChangesAsync(); diff --git a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs index 6396d3f5d..c42b1975e 100644 --- a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs +++ b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs @@ -19,7 +19,7 @@ { if (!context.Campaigns.Any()) { - context.Campaigns.AddRange( + await context.Campaigns.AddRangeAsync( GetPreconfiguredMarketings()); await context.SaveChangesAsync(); diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs index 53c53f052..4f3f0b0f2 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/OrderingContextSeed.cs @@ -39,7 +39,7 @@ if (!context.CardTypes.Any()) { - context.CardTypes.AddRange(useCustomizationData + await context.CardTypes.AddRangeAsync(useCustomizationData ? GetCardTypesFromFile(contentRootPath, logger) : GetPredefinedCardTypes()); @@ -48,7 +48,7 @@ if (!context.OrderStatus.Any()) { - context.OrderStatus.AddRange(useCustomizationData + await context.OrderStatus.AddRangeAsync(useCustomizationData ? GetOrderStatusFromFile(contentRootPath, logger) : GetPredefinedOrderStatus()); } From 48b273c9b279ccbcce8aa45c3eda3666f3d93b2e Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 19 Feb 2018 16:48:34 +0000 Subject: [PATCH 3/4] Rely on TinyIoC defaults to register interface mappings as singletons. --- .../ViewModels/Base/ViewModelLocator.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs index 22b8bc99d..9548583bb 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs @@ -42,11 +42,11 @@ namespace eShopOnContainers.Core.ViewModels.Base { _container = new TinyIoCContainer(); - // View models + // View models - by default, TinyIoC will register concrete classes as multi-instance. _container.Register(); _container.Register(); _container.Register(); - _container.Register(); + _container.Register().AsSingleton(); _container.Register(); _container.Register(); _container.Register(); @@ -54,21 +54,21 @@ namespace eShopOnContainers.Core.ViewModels.Base _container.Register(); _container.Register(); - // Services - _container.Register().AsSingleton(); + // Services - by default, TinyIoC will register interface registrations as singletons. + _container.Register(); _container.Register(); _container.Register(); _container.Register(); - _container.Register(); + _container.Register().AsMultiInstance(); _container.Register(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); } public static void UpdateDependencies(bool useMockServices) @@ -76,21 +76,21 @@ namespace eShopOnContainers.Core.ViewModels.Base // Change injected dependencies if (useMockServices) { - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); UseMockService = true; } else { - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); - _container.Register().AsSingleton(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); + _container.Register(); UseMockService = false; } From 68d0783070dcbc84b7cc644ee0f638e7ceecfaed Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 19 Feb 2018 16:59:29 +0000 Subject: [PATCH 4/4] Removed TinyIoC behavior overrides. --- .../ViewModels/Base/ViewModelLocator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs index 9548583bb..8a6b6356a 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs @@ -46,7 +46,7 @@ namespace eShopOnContainers.Core.ViewModels.Base _container.Register(); _container.Register(); _container.Register(); - _container.Register().AsSingleton(); + _container.Register(); _container.Register(); _container.Register(); _container.Register(); @@ -59,7 +59,7 @@ namespace eShopOnContainers.Core.ViewModels.Base _container.Register(); _container.Register(); _container.Register(); - _container.Register().AsMultiInstance(); + _container.Register(); _container.Register(); _container.Register(); _container.Register();