From 084db74c77de548c5e3c928967fb686022a8cc54 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Mon, 7 Aug 2017 10:08:41 -0400 Subject: [PATCH] data refactor (#27) * Refactoring to move data access code into Infrastructure project * Fixing namespaces --- .../Data}/CatalogContext.cs | 2 +- .../Data}/CatalogContextSeed.cs | 19 +++++++++---------- .../20170302162241_Initial.Designer.cs | 2 +- .../Migrations/20170302162241_Initial.cs | 2 +- .../Migrations/CatalogContextModelSnapshot.cs | 2 +- .../Services/BasketService.cs | 2 +- .../ICatalogService.cs | 0 src/Web/Services/CatalogService.cs | 2 +- src/Web/Startup.cs | 4 ++-- 9 files changed, 17 insertions(+), 18 deletions(-) rename src/{Web/Infrastructure => Infrastructure/Data}/CatalogContext.cs (98%) rename src/{Web/Infrastructure => Infrastructure/Data}/CatalogContextSeed.cs (94%) rename src/{Web/Infrastructure => Infrastructure/Data}/Migrations/20170302162241_Initial.Designer.cs (98%) rename src/{Web/Infrastructure => Infrastructure/Data}/Migrations/20170302162241_Initial.cs (98%) rename src/{Web/Infrastructure => Infrastructure/Data}/Migrations/CatalogContextModelSnapshot.cs (98%) rename src/{Web => Infrastructure}/Services/BasketService.cs (97%) rename src/Web/{Services => Interfaces}/ICatalogService.cs (100%) diff --git a/src/Web/Infrastructure/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs similarity index 98% rename from src/Web/Infrastructure/CatalogContext.cs rename to src/Infrastructure/Data/CatalogContext.cs index 939ec97..9663c90 100644 --- a/src/Web/Infrastructure/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.eShopWeb.ApplicationCore.Entities; -namespace Microsoft.eShopWeb.Infrastructure +namespace Infrastructure.Data { public class CatalogContext : DbContext diff --git a/src/Web/Infrastructure/CatalogContextSeed.cs b/src/Infrastructure/Data/CatalogContextSeed.cs similarity index 94% rename from src/Web/Infrastructure/CatalogContextSeed.cs rename to src/Infrastructure/Data/CatalogContextSeed.cs index ec7034c..a7c1845 100644 --- a/src/Web/Infrastructure/CatalogContextSeed.cs +++ b/src/Infrastructure/Data/CatalogContextSeed.cs @@ -1,14 +1,13 @@ -namespace Microsoft.eShopWeb.Infrastructure -{ - using Microsoft.AspNetCore.Builder; - using Microsoft.EntityFrameworkCore; - using Microsoft.eShopWeb.ApplicationCore.Entities; - using Microsoft.Extensions.Logging; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +namespace Infrastructure.Data +{ public class CatalogContextSeed { public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory, int? retry = 0) diff --git a/src/Web/Infrastructure/Migrations/20170302162241_Initial.Designer.cs b/src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs similarity index 98% rename from src/Web/Infrastructure/Migrations/20170302162241_Initial.Designer.cs rename to src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs index 382f8d6..e546fbe 100644 --- a/src/Web/Infrastructure/Migrations/20170302162241_Initial.Designer.cs +++ b/src/Infrastructure/Data/Migrations/20170302162241_Initial.Designer.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; -namespace Microsoft.eShopWeb.Infrastructure.Migrations +namespace Infrastructure.Data.Migrations { [DbContext(typeof(CatalogContext))] [Migration("20170302162241_Initial")] diff --git a/src/Web/Infrastructure/Migrations/20170302162241_Initial.cs b/src/Infrastructure/Data/Migrations/20170302162241_Initial.cs similarity index 98% rename from src/Web/Infrastructure/Migrations/20170302162241_Initial.cs rename to src/Infrastructure/Data/Migrations/20170302162241_Initial.cs index 3817256..009daf6 100644 --- a/src/Web/Infrastructure/Migrations/20170302162241_Initial.cs +++ b/src/Infrastructure/Data/Migrations/20170302162241_Initial.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; -namespace Microsoft.eShopWeb.Infrastructure.Migrations +namespace Infrastructure.Data.Migrations { public partial class Initial : Migration { diff --git a/src/Web/Infrastructure/Migrations/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs similarity index 98% rename from src/Web/Infrastructure/Migrations/CatalogContextModelSnapshot.cs rename to src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index 339e6d6..937b9ec 100644 --- a/src/Web/Infrastructure/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -namespace Microsoft.eShopWeb.Infrastructure.Migrations +namespace Infrastructure.Data.Migrations { [DbContext(typeof(CatalogContext))] partial class CatalogContextModelSnapshot : ModelSnapshot diff --git a/src/Web/Services/BasketService.cs b/src/Infrastructure/Services/BasketService.cs similarity index 97% rename from src/Web/Services/BasketService.cs rename to src/Infrastructure/Services/BasketService.cs index b07d4da..6bd8b0d 100644 --- a/src/Web/Services/BasketService.cs +++ b/src/Infrastructure/Services/BasketService.cs @@ -1,9 +1,9 @@ using ApplicationCore.Interfaces; using System.Threading.Tasks; using Microsoft.eShopWeb.ApplicationCore.Entities; -using Microsoft.eShopWeb.Infrastructure; using Microsoft.EntityFrameworkCore; using System; +using Infrastructure.Data; namespace Web.Services { diff --git a/src/Web/Services/ICatalogService.cs b/src/Web/Interfaces/ICatalogService.cs similarity index 100% rename from src/Web/Services/ICatalogService.cs rename to src/Web/Interfaces/ICatalogService.cs diff --git a/src/Web/Services/CatalogService.cs b/src/Web/Services/CatalogService.cs index 52dbed9..ef8e32c 100644 --- a/src/Web/Services/CatalogService.cs +++ b/src/Web/Services/CatalogService.cs @@ -4,12 +4,12 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -using Microsoft.eShopWeb.Infrastructure; using Microsoft.eShopWeb.ViewModels; using Microsoft.eShopWeb.ApplicationCore.Entities; using System.Data.SqlClient; using Dapper; using Microsoft.Extensions.Logging; +using Infrastructure.Data; namespace Microsoft.eShopWeb.Services { diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index 156282e..0abbd9b 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -1,5 +1,4 @@ -using Microsoft.eShopWeb.Infrastructure; -using Microsoft.eShopWeb.Services; +using Microsoft.eShopWeb.Services; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; @@ -17,6 +16,7 @@ using Infrastructure.Logging; using Microsoft.AspNetCore.Identity; using Web.Services; using ApplicationCore.Services; +using Infrastructure.Data; namespace Microsoft.eShopWeb {