diff --git a/Directory.Packages.props b/Directory.Packages.props
index f371ed6..20f7106 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -5,7 +5,7 @@
8.0.1
8.1.0
8.0.1
- 8.0.0-preview.3.24078.5
+ 8.0.0-preview.3.24081.13
2.59.0
diff --git a/eShop.sln b/eShop.sln
index 75f54b1..cb4fa90 100644
--- a/eShop.sln
+++ b/eShop.sln
@@ -28,6 +28,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Keycloak", "Keycloak", "{08
src\Keycloak\data\import\eshop-realm.json = src\Keycloak\data\import\eshop-realm.json
EndProjectSection
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Catalog.Data", "src\Catalog.Data\Catalog.Data.csproj", "{BFF57633-BF05-4D32-826C-212AE7858539}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Catalog.Data.Manager", "src\Catalog.Data.Manager\Catalog.Data.Manager.csproj", "{E1AAD2C8-97A7-404E-9DF7-89A719101631}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.Data", "src\Ordering.Data\Ordering.Data.csproj", "{D68FAD25-C09D-434C-A7AE-8F78DB2D923D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ordering.Data.Manager", "src\Ordering.Data.Manager\Ordering.Data.Manager.csproj", "{4FCA8863-B3C7-47D6-B031-37A0384B40AA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -58,6 +66,22 @@ Global
{2F3143A9-1565-43BF-8BF2-18B13F604CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F3143A9-1565-43BF-8BF2-18B13F604CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F3143A9-1565-43BF-8BF2-18B13F604CE9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BFF57633-BF05-4D32-826C-212AE7858539}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BFF57633-BF05-4D32-826C-212AE7858539}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BFF57633-BF05-4D32-826C-212AE7858539}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BFF57633-BF05-4D32-826C-212AE7858539}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E1AAD2C8-97A7-404E-9DF7-89A719101631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E1AAD2C8-97A7-404E-9DF7-89A719101631}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E1AAD2C8-97A7-404E-9DF7-89A719101631}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E1AAD2C8-97A7-404E-9DF7-89A719101631}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D68FAD25-C09D-434C-A7AE-8F78DB2D923D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D68FAD25-C09D-434C-A7AE-8F78DB2D923D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D68FAD25-C09D-434C-A7AE-8F78DB2D923D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D68FAD25-C09D-434C-A7AE-8F78DB2D923D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4FCA8863-B3C7-47D6-B031-37A0384B40AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4FCA8863-B3C7-47D6-B031-37A0384B40AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4FCA8863-B3C7-47D6-B031-37A0384B40AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4FCA8863-B3C7-47D6-B031-37A0384B40AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/global.json b/global.json
index 75a5bd4..f868b0c 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "8.0.200-preview",
+ "version": "8.0.200-preview.23624.5",
"rollForward": "latestPatch",
"allowPrerelease": true
}
diff --git a/nuget.config b/nuget.config
index e4eb8ce..a495f63 100644
--- a/nuget.config
+++ b/nuget.config
@@ -2,14 +2,14 @@
-
+
-
+
diff --git a/src/Catalog.API/Apis/CatalogApi.cs b/src/Catalog.API/Apis/CatalogApi.cs
index 2ce6ae6..015eed9 100644
--- a/src/Catalog.API/Apis/CatalogApi.cs
+++ b/src/Catalog.API/Apis/CatalogApi.cs
@@ -2,8 +2,8 @@
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using eShop.Catalog.API;
-using eShop.Catalog.API.Data;
using eShop.Catalog.API.Model;
+using eShop.Catalog.Data;
namespace Microsoft.AspNetCore.Builder;
@@ -180,17 +180,17 @@ public static async Task>> GetItemsByBrandId(
var pageSize = paginationRequest.PageSize;
var pageIndex = paginationRequest.PageIndex;
- var root = (IQueryable)services.DbContext.CatalogItems;
+ var query = (IQueryable)services.DbContext.CatalogItems;
if (brandId is not null)
{
- root = root.Where(ci => ci.CatalogBrandId == brandId);
+ query = query.Where(ci => ci.CatalogBrandId == brandId);
}
- var totalItems = await root
+ var totalItems = await query
.LongCountAsync();
- var itemsOnPage = await root
+ var itemsOnPage = await query
.Skip(pageSize * pageIndex)
.Take(pageSize)
.AsNoTracking()
diff --git a/src/Catalog.API/Catalog.API.csproj b/src/Catalog.API/Catalog.API.csproj
index 1561829..9b3e732 100644
--- a/src/Catalog.API/Catalog.API.csproj
+++ b/src/Catalog.API/Catalog.API.csproj
@@ -8,25 +8,8 @@
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
+
-
-
-
-
-
diff --git a/src/Catalog.API/CatalogOptions.cs b/src/Catalog.API/CatalogOptions.cs
index a2b0048..0e0c2af 100644
--- a/src/Catalog.API/CatalogOptions.cs
+++ b/src/Catalog.API/CatalogOptions.cs
@@ -10,8 +10,6 @@ public class CatalogOptions
public string PicBasePathFormat { get; set; } = "items/{0}/pic/";
- public bool UseCustomizationData { get; set; }
-
public string GetPictureUrl(int catalogItemId)
{
// PERF: Not ideal
diff --git a/src/Catalog.API/Extensions/HostingExtensions.cs b/src/Catalog.API/Extensions/HostingExtensions.cs
index e80a1fa..7b8af1e 100644
--- a/src/Catalog.API/Extensions/HostingExtensions.cs
+++ b/src/Catalog.API/Extensions/HostingExtensions.cs
@@ -1,5 +1,5 @@
using eShop.Catalog.API;
-using eShop.Catalog.API.Data;
+using eShop.Catalog.Data;
using Microsoft.Extensions.Options;
namespace Microsoft.Extensions.Hosting;
@@ -10,9 +10,6 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddNpgsqlDbContext("CatalogDB");
- // TODO: Move this to a CatalogDbManager project
- builder.Services.AddMigration();
-
builder.Services.Configure(builder.Configuration.GetSection(nameof(CatalogOptions)));
}
diff --git a/src/Catalog.API/Model/CatalogServices.cs b/src/Catalog.API/Model/CatalogServices.cs
index 6b6731e..1d42ca9 100644
--- a/src/Catalog.API/Model/CatalogServices.cs
+++ b/src/Catalog.API/Model/CatalogServices.cs
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Options;
-using eShop.Catalog.API.Data;
+using eShop.Catalog.Data;
namespace eShop.Catalog.API.Model;
diff --git a/src/Catalog.API/appsettings.Development.json b/src/Catalog.API/appsettings.Development.json
index e7ffc1c..14f85db 100644
--- a/src/Catalog.API/appsettings.Development.json
+++ b/src/Catalog.API/appsettings.Development.json
@@ -3,6 +3,6 @@
"CatalogDB": "Host=localhost;Database=CatalogDB;Username=postgres"
},
"CatalogOptions": {
- "PicBasePathFormat": "items/{0}/pic/"
+
}
}
\ No newline at end of file
diff --git a/src/Catalog.API/appsettings.json b/src/Catalog.API/appsettings.json
index dd150a5..1e08a06 100644
--- a/src/Catalog.API/appsettings.json
+++ b/src/Catalog.API/appsettings.json
@@ -22,6 +22,6 @@
"SubscriptionClientName": "Catalog"
},
"CatalogOptions": {
- "UseCustomizationData": false
+ "PicBasePathFormat": "items/{0}/pic/"
}
}
diff --git a/src/Catalog.Data.Manager/Catalog.Data.Manager.csproj b/src/Catalog.Data.Manager/Catalog.Data.Manager.csproj
new file mode 100644
index 0000000..271e934
--- /dev/null
+++ b/src/Catalog.Data.Manager/Catalog.Data.Manager.csproj
@@ -0,0 +1,28 @@
+
+
+
+ net8.0
+ eShop.Catalog.Data.Manager
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/src/Catalog.API/Data/CatalogContextSeed.cs b/src/Catalog.Data.Manager/CatalogContextSeed.cs
similarity index 93%
rename from src/Catalog.API/Data/CatalogContextSeed.cs
rename to src/Catalog.Data.Manager/CatalogContextSeed.cs
index c5da4dc..ed667c7 100644
--- a/src/Catalog.API/Data/CatalogContextSeed.cs
+++ b/src/Catalog.Data.Manager/CatalogContextSeed.cs
@@ -1,16 +1,14 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.Options;
using Npgsql;
-namespace eShop.Catalog.API.Data;
+namespace eShop.Catalog.Data.Manager;
-public partial class CatalogContextSeed(IWebHostEnvironment env, IOptions settings, ILogger logger)
+public partial class CatalogContextSeed(IWebHostEnvironment env, ILogger logger)
: IDbSeeder
{
public async Task SeedAsync(CatalogDbContext context)
{
- var useCustomizationData = settings.Value.UseCustomizationData;
var contentRootPath = env.ContentRootPath;
var picturePath = env.WebRootPath;
diff --git a/src/Catalog.API/Data/Migrations/20231009153249_Initial.Designer.cs b/src/Catalog.Data.Manager/Migrations/20231009153249_Initial.Designer.cs
similarity index 95%
rename from src/Catalog.API/Data/Migrations/20231009153249_Initial.Designer.cs
rename to src/Catalog.Data.Manager/Migrations/20231009153249_Initial.Designer.cs
index 712b1b5..92b11fc 100644
--- a/src/Catalog.API/Data/Migrations/20231009153249_Initial.Designer.cs
+++ b/src/Catalog.Data.Manager/Migrations/20231009153249_Initial.Designer.cs
@@ -3,13 +3,13 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using eShop.Catalog.API.Data;
+using eShop.Catalog.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
//using Pgvector;
#nullable disable
-namespace eShop.Catalog.API.Data.Migrations
+namespace eShop.Catalog.Data.Manager.Migrations
{
[DbContext(typeof(CatalogDbContext))]
[Migration("20231009153249_Initial")]
@@ -20,10 +20,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "8.0.0-rtm.23512.13")
+ .HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
- //NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "vector");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.HasSequence("catalog_brand_hilo")
diff --git a/src/Catalog.API/Data/Migrations/20231009153249_Initial.cs b/src/Catalog.Data.Manager/Migrations/20231009153249_Initial.cs
similarity index 99%
rename from src/Catalog.API/Data/Migrations/20231009153249_Initial.cs
rename to src/Catalog.Data.Manager/Migrations/20231009153249_Initial.cs
index b5a00fb..97c2422 100644
--- a/src/Catalog.API/Data/Migrations/20231009153249_Initial.cs
+++ b/src/Catalog.Data.Manager/Migrations/20231009153249_Initial.cs
@@ -2,7 +2,7 @@
#nullable disable
-namespace eShop.Catalog.API.Data.Migrations
+namespace eShop.Catalog.Data.Manager.Migrations
{
///
public partial class Initial : Migration
diff --git a/src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs b/src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs
similarity index 98%
rename from src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs
rename to src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs
index f095561..8f46505 100644
--- a/src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs
+++ b/src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.Designer.cs
@@ -3,13 +3,13 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using eShop.Catalog.API.Data;
+using eShop.Catalog.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
//using Pgvector;
#nullable disable
-namespace eShop.Catalog.API.Data.Migrations
+namespace eShop.Catalog.Data.Manager.Migrations
{
[DbContext(typeof(CatalogDbContext))]
[Migration("20231018163051_RemoveHiLoAndIndexCatalogName")]
diff --git a/src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs b/src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs
similarity index 98%
rename from src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs
rename to src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs
index 5f336ce..2f6de03 100644
--- a/src/Catalog.API/Data/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs
+++ b/src/Catalog.Data.Manager/Migrations/20231018163051_RemoveHiLoAndIndexCatalogName.cs
@@ -3,7 +3,7 @@
#nullable disable
-namespace eShop.Catalog.API.Data.Migrations
+namespace eShop.Catalog.Data.Manager.Migrations
{
///
public partial class RemoveHiLoAndIndexCatalogName : Migration
diff --git a/src/Catalog.API/Data/Migrations/CatalogContextModelSnapshot.cs b/src/Catalog.Data.Manager/Migrations/CatalogContextModelSnapshot.cs
similarity index 86%
rename from src/Catalog.API/Data/Migrations/CatalogContextModelSnapshot.cs
rename to src/Catalog.Data.Manager/Migrations/CatalogContextModelSnapshot.cs
index 9721cc1..d5d0186 100644
--- a/src/Catalog.API/Data/Migrations/CatalogContextModelSnapshot.cs
+++ b/src/Catalog.Data.Manager/Migrations/CatalogContextModelSnapshot.cs
@@ -3,12 +3,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using eShop.Catalog.API.Data;
+using eShop.Catalog.Data;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
-namespace eShop.Catalog.API.Data.Migrations
+namespace eShop.Catalog.Data.Manager.Migrations
{
[DbContext(typeof(CatalogDbContext))]
partial class CatalogContextModelSnapshot : ModelSnapshot
@@ -17,12 +17,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "8.0.0-rtm.23512.13")
+ .HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
- modelBuilder.Entity("eShop.Catalog.API.Model.CatalogBrand", b =>
+ modelBuilder.Entity("eShop.Catalog.Data.CatalogBrand", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
@@ -40,7 +40,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("CatalogBrand", (string)null);
});
- modelBuilder.Entity("eShop.Catalog.API.Model.CatalogItem", b =>
+ modelBuilder.Entity("eShop.Catalog.Data.CatalogItem", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
@@ -91,7 +91,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Catalog", (string)null);
});
- modelBuilder.Entity("eShop.Catalog.API.Model.CatalogType", b =>
+ modelBuilder.Entity("eShop.Catalog.Data.CatalogType", b =>
{
b.Property("Id")
.ValueGeneratedOnAdd()
@@ -109,15 +109,15 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("CatalogType", (string)null);
});
- modelBuilder.Entity("eShop.Catalog.API.Model.CatalogItem", b =>
+ modelBuilder.Entity("eShop.Catalog.Data.CatalogItem", b =>
{
- b.HasOne("eShop.Catalog.API.Model.CatalogBrand", "CatalogBrand")
+ b.HasOne("eShop.Catalog.Data.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- b.HasOne("eShop.Catalog.API.Model.CatalogType", "CatalogType")
+ b.HasOne("eShop.Catalog.Data.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade)
diff --git a/src/Catalog.Data.Manager/Program.cs b/src/Catalog.Data.Manager/Program.cs
new file mode 100644
index 0000000..4709d4a
--- /dev/null
+++ b/src/Catalog.Data.Manager/Program.cs
@@ -0,0 +1,19 @@
+using eShop.Catalog.Data;
+using eShop.Catalog.Data.Manager;
+using Microsoft.EntityFrameworkCore;
+
+var builder = WebApplication.CreateBuilder(args);
+
+builder.AddServiceDefaults();
+
+builder.AddNpgsqlDbContext("CatalogDB", null,
+ optionsBuilder => optionsBuilder.UseNpgsql(npgsqlBuilder =>
+ npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name)));
+
+builder.Services.AddMigration();
+
+var app = builder.Build();
+
+app.MapDefaultEndpoints();
+
+app.Run();
diff --git a/src/Catalog.Data.Manager/Properties/launchSettings.json b/src/Catalog.Data.Manager/Properties/launchSettings.json
new file mode 100644
index 0000000..5d97802
--- /dev/null
+++ b/src/Catalog.Data.Manager/Properties/launchSettings.json
@@ -0,0 +1,25 @@
+{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "health",
+ "applicationUrl": "http://localhost:5035",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "health",
+ "applicationUrl": "https://localhost:7014;http://localhost:5035",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/src/Catalog.API/Setup/catalog.json b/src/Catalog.Data.Manager/Setup/catalog.json
similarity index 100%
rename from src/Catalog.API/Setup/catalog.json
rename to src/Catalog.Data.Manager/Setup/catalog.json
diff --git a/src/Catalog.Data.Manager/appsettings.Development.json b/src/Catalog.Data.Manager/appsettings.Development.json
new file mode 100644
index 0000000..61cc733
--- /dev/null
+++ b/src/Catalog.Data.Manager/appsettings.Development.json
@@ -0,0 +1,11 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "ConnectionStrings": {
+ "CatalogDB": "Host=localhost;Database=CatalogDB;Username=postgres"
+ }
+}
diff --git a/src/Catalog.Data.Manager/appsettings.json b/src/Catalog.Data.Manager/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/src/Catalog.Data.Manager/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/src/Catalog.Data/Catalog.Data.csproj b/src/Catalog.Data/Catalog.Data.csproj
new file mode 100644
index 0000000..95f2828
--- /dev/null
+++ b/src/Catalog.Data/Catalog.Data.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net8.0
+ eShop.Catalog.Data
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/src/Catalog.API/Data/CatalogBrand.cs b/src/Catalog.Data/CatalogBrand.cs
similarity index 83%
rename from src/Catalog.API/Data/CatalogBrand.cs
rename to src/Catalog.Data/CatalogBrand.cs
index 6c8f312..353a4ad 100644
--- a/src/Catalog.API/Data/CatalogBrand.cs
+++ b/src/Catalog.Data/CatalogBrand.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Catalog.API.Data;
+namespace eShop.Catalog.Data;
public class CatalogBrand
{
diff --git a/src/Catalog.API/Data/CatalogDbContext.cs b/src/Catalog.Data/CatalogDbContext.cs
similarity index 81%
rename from src/Catalog.API/Data/CatalogDbContext.cs
rename to src/Catalog.Data/CatalogDbContext.cs
index 2ef61d2..316eb79 100644
--- a/src/Catalog.API/Data/CatalogDbContext.cs
+++ b/src/Catalog.Data/CatalogDbContext.cs
@@ -1,12 +1,12 @@
using Microsoft.EntityFrameworkCore;
-using eShop.Catalog.API.Data.EntityConfigurations;
+using eShop.Catalog.Data.EntityConfigurations;
-namespace eShop.Catalog.API.Data;
+namespace eShop.Catalog.Data;
///
-/// Add migrations using the following command inside the 'Catalog.API' project directory:
+/// Add migrations using the following command inside the 'Catalog.Data.Manager' project directory:
///
-/// dotnet ef migrations add --context CatalogContext [migration-name]
+/// dotnet ef migrations add --context CatalogDbContext [migration-name]
///
public class CatalogDbContext(DbContextOptions options) : DbContext(options)
{
diff --git a/src/Catalog.API/Data/CatalogItem.cs b/src/Catalog.Data/CatalogItem.cs
similarity index 97%
rename from src/Catalog.API/Data/CatalogItem.cs
rename to src/Catalog.Data/CatalogItem.cs
index 28ee8f5..a2f3538 100644
--- a/src/Catalog.API/Data/CatalogItem.cs
+++ b/src/Catalog.Data/CatalogItem.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Catalog.API.Data;
+namespace eShop.Catalog.Data;
public class CatalogItem
{
diff --git a/src/Catalog.API/Data/CatalogType.cs b/src/Catalog.Data/CatalogType.cs
similarity index 83%
rename from src/Catalog.API/Data/CatalogType.cs
rename to src/Catalog.Data/CatalogType.cs
index cc3378f..93f5548 100644
--- a/src/Catalog.API/Data/CatalogType.cs
+++ b/src/Catalog.Data/CatalogType.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Catalog.API.Data;
+namespace eShop.Catalog.Data;
public class CatalogType
{
diff --git a/src/Catalog.API/Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs b/src/Catalog.Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs
similarity index 87%
rename from src/Catalog.API/Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs
rename to src/Catalog.Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs
index 4184863..2017ec2 100644
--- a/src/Catalog.API/Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs
+++ b/src/Catalog.Data/EntityConfigurations/CatalogBrandEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Catalog.API.Data.EntityConfigurations;
+namespace eShop.Catalog.Data.EntityConfigurations;
internal class CatalogBrandEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Catalog.API/Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs b/src/Catalog.Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
similarity index 91%
rename from src/Catalog.API/Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
rename to src/Catalog.Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
index 7edfbe3..faf6cfc 100644
--- a/src/Catalog.API/Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
+++ b/src/Catalog.Data/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Catalog.API.Data.EntityConfigurations;
+namespace eShop.Catalog.Data.EntityConfigurations;
internal class CatalogItemEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Catalog.API/Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs b/src/Catalog.Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs
similarity index 87%
rename from src/Catalog.API/Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs
rename to src/Catalog.Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs
index 54fe9ae..ed05cb1 100644
--- a/src/Catalog.API/Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs
+++ b/src/Catalog.Data/EntityConfigurations/CatalogTypeEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Catalog.API.Data.EntityConfigurations;
+namespace eShop.Catalog.Data.EntityConfigurations;
internal class CatalogTypeEntityTypeConfiguration: IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Apis/OrdersApi.cs b/src/Ordering.API/Apis/OrdersApi.cs
index 56c3ead..68774f9 100644
--- a/src/Ordering.API/Apis/OrdersApi.cs
+++ b/src/Ordering.API/Apis/OrdersApi.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data;
using eShop.Ordering.API.Model;
using MinimalApis.Extensions.Filters;
diff --git a/src/Ordering.API/Extensions/HostingExtensions.cs b/src/Ordering.API/Extensions/HostingExtensions.cs
index a59f357..8f6d376 100644
--- a/src/Ordering.API/Extensions/HostingExtensions.cs
+++ b/src/Ordering.API/Extensions/HostingExtensions.cs
@@ -1,4 +1,4 @@
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data;
using eShop.Ordering.API.Services;
namespace Microsoft.Extensions.Hosting;
@@ -14,8 +14,6 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)
builder.AddNpgsqlDbContext("OrderingDB");
- services.AddMigration();
-
services.AddHttpContextAccessor();
services.AddTransient();
}
diff --git a/src/Ordering.API/Model/OrderServices.cs b/src/Ordering.API/Model/OrderServices.cs
index 8c3fe70..9a3b9a5 100644
--- a/src/Ordering.API/Model/OrderServices.cs
+++ b/src/Ordering.API/Model/OrderServices.cs
@@ -1,4 +1,4 @@
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data;
using eShop.Ordering.API.Services;
namespace eShop.Ordering.API.Model;
diff --git a/src/Ordering.API/Model/OrderSummary.cs b/src/Ordering.API/Model/OrderSummary.cs
index fd826f5..f2c5dce 100644
--- a/src/Ordering.API/Model/OrderSummary.cs
+++ b/src/Ordering.API/Model/OrderSummary.cs
@@ -1,4 +1,4 @@
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data;
namespace eShop.Ordering.API.Model;
diff --git a/src/Ordering.API/Ordering.API.csproj b/src/Ordering.API/Ordering.API.csproj
index 7c5a7fb..da6ac5c 100644
--- a/src/Ordering.API/Ordering.API.csproj
+++ b/src/Ordering.API/Ordering.API.csproj
@@ -4,29 +4,18 @@
net8.0
eShop.Ordering.API
7161b768-033d-41c7-bc5d-37528275e1f3
+ enable
enable
-
-
-
-
-
+
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Ordering.API/Data/Migrations/20240126233459_Initial.Designer.cs b/src/Ordering.Data.Manager/Migrations/20240126233459_Initial.Designer.cs
similarity index 99%
rename from src/Ordering.API/Data/Migrations/20240126233459_Initial.Designer.cs
rename to src/Ordering.Data.Manager/Migrations/20240126233459_Initial.Designer.cs
index 039ce7e..130d969 100644
--- a/src/Ordering.API/Data/Migrations/20240126233459_Initial.Designer.cs
+++ b/src/Ordering.Data.Manager/Migrations/20240126233459_Initial.Designer.cs
@@ -5,11 +5,11 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data.Manager;
#nullable disable
-namespace eShop.Ordering.API.Data.Migrations
+namespace eShop.Ordering.Data.Manager.Migrations
{
[DbContext(typeof(OrderingDbContext))]
[Migration("20240126233459_Initial")]
diff --git a/src/Ordering.API/Data/Migrations/20240126233459_Initial.cs b/src/Ordering.Data.Manager/Migrations/20240126233459_Initial.cs
similarity index 99%
rename from src/Ordering.API/Data/Migrations/20240126233459_Initial.cs
rename to src/Ordering.Data.Manager/Migrations/20240126233459_Initial.cs
index a1c15cf..f20203b 100644
--- a/src/Ordering.API/Data/Migrations/20240126233459_Initial.cs
+++ b/src/Ordering.Data.Manager/Migrations/20240126233459_Initial.cs
@@ -3,7 +3,7 @@
#nullable disable
-namespace eShop.Ordering.API.Data.Migrations
+namespace eShop.Ordering.Data.Manager.Migrations
{
///
public partial class Initial : Migration
diff --git a/src/Ordering.API/Data/Migrations/OrderingDbContextModelSnapshot.cs b/src/Ordering.Data.Manager/Migrations/OrderingDbContextModelSnapshot.cs
similarity index 99%
rename from src/Ordering.API/Data/Migrations/OrderingDbContextModelSnapshot.cs
rename to src/Ordering.Data.Manager/Migrations/OrderingDbContextModelSnapshot.cs
index 52f5524..d8e98c0 100644
--- a/src/Ordering.API/Data/Migrations/OrderingDbContextModelSnapshot.cs
+++ b/src/Ordering.Data.Manager/Migrations/OrderingDbContextModelSnapshot.cs
@@ -4,11 +4,11 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using eShop.Ordering.API.Data;
+using eShop.Ordering.Data.Manager;
#nullable disable
-namespace eShop.Ordering.API.Data.Migrations
+namespace eShop.Ordering.Data.Manager.Migrations
{
[DbContext(typeof(OrderingDbContext))]
partial class OrderingDbContextModelSnapshot : ModelSnapshot
diff --git a/src/Ordering.Data.Manager/Ordering.Data.Manager.csproj b/src/Ordering.Data.Manager/Ordering.Data.Manager.csproj
new file mode 100644
index 0000000..b1d2312
--- /dev/null
+++ b/src/Ordering.Data.Manager/Ordering.Data.Manager.csproj
@@ -0,0 +1,28 @@
+
+
+
+ net8.0
+ eShop.Ordering.Data.Manager
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/src/Ordering.API/Data/OrderingDbContextSeed.cs b/src/Ordering.Data.Manager/OrderingDbContextSeed.cs
similarity index 92%
rename from src/Ordering.API/Data/OrderingDbContextSeed.cs
rename to src/Ordering.Data.Manager/OrderingDbContextSeed.cs
index 5c92ce1..0e505b0 100644
--- a/src/Ordering.API/Data/OrderingDbContextSeed.cs
+++ b/src/Ordering.Data.Manager/OrderingDbContextSeed.cs
@@ -1,4 +1,4 @@
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data.Manager;
public class OrderingDbContextSeed : IDbSeeder
{
diff --git a/src/Ordering.Data.Manager/Program.cs b/src/Ordering.Data.Manager/Program.cs
new file mode 100644
index 0000000..c7bb933
--- /dev/null
+++ b/src/Ordering.Data.Manager/Program.cs
@@ -0,0 +1,19 @@
+using eShop.Ordering.Data;
+using eShop.Ordering.Data.Manager;
+using Microsoft.EntityFrameworkCore;
+
+var builder = WebApplication.CreateBuilder(args);
+
+builder.AddServiceDefaults();
+
+builder.AddNpgsqlDbContext("OrderingDB", null,
+ optionsBuilder => optionsBuilder.UseNpgsql(npgsqlBuilder =>
+ npgsqlBuilder.MigrationsAssembly(typeof(Program).Assembly.GetName().Name)));
+
+builder.Services.AddMigration();
+
+var app = builder.Build();
+
+app.MapDefaultEndpoints();
+
+app.Run();
diff --git a/src/Ordering.Data.Manager/Properties/launchSettings.json b/src/Ordering.Data.Manager/Properties/launchSettings.json
new file mode 100644
index 0000000..beb062b
--- /dev/null
+++ b/src/Ordering.Data.Manager/Properties/launchSettings.json
@@ -0,0 +1,25 @@
+{
+ "$schema": "http://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "health",
+ "applicationUrl": "http://localhost:5157",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "launchUrl": "health",
+ "applicationUrl": "https://localhost:7013;http://localhost:5157",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/src/Ordering.Data.Manager/appsettings.Development.json b/src/Ordering.Data.Manager/appsettings.Development.json
new file mode 100644
index 0000000..ef07e65
--- /dev/null
+++ b/src/Ordering.Data.Manager/appsettings.Development.json
@@ -0,0 +1,11 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "ConnectionStrings": {
+ "OrderingDB": "Host=localhost;Database=OrderingDB;Username=postgres"
+ }
+}
diff --git a/src/Ordering.Data.Manager/appsettings.json b/src/Ordering.Data.Manager/appsettings.json
new file mode 100644
index 0000000..10f68b8
--- /dev/null
+++ b/src/Ordering.Data.Manager/appsettings.json
@@ -0,0 +1,9 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/src/Ordering.API/Data/Address.cs b/src/Ordering.Data/Address.cs
similarity index 94%
rename from src/Ordering.API/Data/Address.cs
rename to src/Ordering.Data/Address.cs
index 1f8f697..9f3db7f 100644
--- a/src/Ordering.API/Data/Address.cs
+++ b/src/Ordering.Data/Address.cs
@@ -1,4 +1,4 @@
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class Address(string street, string city, string state, string country, string zipCode) : ValueObject
{
diff --git a/src/Ordering.API/Data/Buyer.cs b/src/Ordering.Data/Buyer.cs
similarity index 90%
rename from src/Ordering.API/Data/Buyer.cs
rename to src/Ordering.Data/Buyer.cs
index 9b14732..7ae8b2e 100644
--- a/src/Ordering.API/Data/Buyer.cs
+++ b/src/Ordering.Data/Buyer.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class Buyer
{
diff --git a/src/Ordering.API/Data/CardType.cs b/src/Ordering.Data/CardType.cs
similarity index 89%
rename from src/Ordering.API/Data/CardType.cs
rename to src/Ordering.Data/CardType.cs
index 992ff58..dfcaad0 100644
--- a/src/Ordering.API/Data/CardType.cs
+++ b/src/Ordering.Data/CardType.cs
@@ -1,4 +1,4 @@
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class CardType : Enumeration
{
diff --git a/src/Ordering.API/Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs b/src/Ordering.Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs
similarity index 92%
rename from src/Ordering.API/Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs
rename to src/Ordering.Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs
index 56daa7e..c03fa34 100644
--- a/src/Ordering.API/Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs
+++ b/src/Ordering.Data/EntityConfigurations/BuyerEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Ordering.API.Data.EntityConfigurations;
+namespace eShop.Ordering.Data.EntityConfigurations;
class BuyerEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs b/src/Ordering.Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs
similarity index 89%
rename from src/Ordering.API/Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs
rename to src/Ordering.Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs
index d903adc..efa5b6f 100644
--- a/src/Ordering.API/Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs
+++ b/src/Ordering.Data/EntityConfigurations/CardTypeEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Ordering.API.Data.EntityConfigurations;
+namespace eShop.Ordering.Data.EntityConfigurations;
class CardTypeEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Data/EntityConfigurations/OrderEntityTypeConfiguration.cs b/src/Ordering.Data/EntityConfigurations/OrderEntityTypeConfiguration.cs
similarity index 96%
rename from src/Ordering.API/Data/EntityConfigurations/OrderEntityTypeConfiguration.cs
rename to src/Ordering.Data/EntityConfigurations/OrderEntityTypeConfiguration.cs
index 1418476..9558d1d 100644
--- a/src/Ordering.API/Data/EntityConfigurations/OrderEntityTypeConfiguration.cs
+++ b/src/Ordering.Data/EntityConfigurations/OrderEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Ordering.API.Data.EntityConfigurations;
+namespace eShop.Ordering.Data.EntityConfigurations;
class OrderEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs b/src/Ordering.Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
similarity index 95%
rename from src/Ordering.API/Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
rename to src/Ordering.Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
index 35e34f8..cd6b756 100644
--- a/src/Ordering.API/Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
+++ b/src/Ordering.Data/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Ordering.API.Data.EntityConfigurations;
+namespace eShop.Ordering.Data.EntityConfigurations;
class OrderItemEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs b/src/Ordering.Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs
similarity index 95%
rename from src/Ordering.API/Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs
rename to src/Ordering.Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs
index 26c1e3d..d32ac6e 100644
--- a/src/Ordering.API/Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs
+++ b/src/Ordering.Data/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace eShop.Ordering.API.Data.EntityConfigurations;
+namespace eShop.Ordering.Data.EntityConfigurations;
class PaymentMethodEntityTypeConfiguration : IEntityTypeConfiguration
{
diff --git a/src/Ordering.API/Data/Enumeration.cs b/src/Ordering.Data/Enumeration.cs
similarity index 98%
rename from src/Ordering.API/Data/Enumeration.cs
rename to src/Ordering.Data/Enumeration.cs
index eb60c7c..44db8ad 100644
--- a/src/Ordering.API/Data/Enumeration.cs
+++ b/src/Ordering.Data/Enumeration.cs
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public abstract class Enumeration : IComparable
{
diff --git a/src/Ordering.API/Data/Order.cs b/src/Ordering.Data/Order.cs
similarity index 91%
rename from src/Ordering.API/Data/Order.cs
rename to src/Ordering.Data/Order.cs
index 852dfd4..996dc18 100644
--- a/src/Ordering.API/Data/Order.cs
+++ b/src/Ordering.Data/Order.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class Order
{
@@ -23,7 +23,7 @@ public class Order
public required PaymentMethod PaymentMethod { get; set; }
- internal decimal GetTotal()
+ public decimal GetTotal()
{
return OrderItems?.Sum(o => (o.Units * o.UnitPrice) - o.Discount) ?? 0;
}
diff --git a/src/Ordering.API/Data/OrderItem.cs b/src/Ordering.Data/OrderItem.cs
similarity index 93%
rename from src/Ordering.API/Data/OrderItem.cs
rename to src/Ordering.Data/OrderItem.cs
index 55ea73e..8c38be8 100644
--- a/src/Ordering.API/Data/OrderItem.cs
+++ b/src/Ordering.Data/OrderItem.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class OrderItem
{
diff --git a/src/Ordering.API/Data/OrderStatus.cs b/src/Ordering.Data/OrderStatus.cs
similarity index 87%
rename from src/Ordering.API/Data/OrderStatus.cs
rename to src/Ordering.Data/OrderStatus.cs
index 274a135..40c9a7f 100644
--- a/src/Ordering.API/Data/OrderStatus.cs
+++ b/src/Ordering.Data/OrderStatus.cs
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum OrderStatus
diff --git a/src/Ordering.Data/Ordering.Data.csproj b/src/Ordering.Data/Ordering.Data.csproj
new file mode 100644
index 0000000..cf8032d
--- /dev/null
+++ b/src/Ordering.Data/Ordering.Data.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ eShop.Ordering.Data
+ enable
+ enable
+
+
+
+
+
+
diff --git a/src/Ordering.API/Data/OrderingDbContext.cs b/src/Ordering.Data/OrderingDbContext.cs
similarity index 81%
rename from src/Ordering.API/Data/OrderingDbContext.cs
rename to src/Ordering.Data/OrderingDbContext.cs
index b4fa0de..cfacaf2 100644
--- a/src/Ordering.API/Data/OrderingDbContext.cs
+++ b/src/Ordering.Data/OrderingDbContext.cs
@@ -1,12 +1,12 @@
using Microsoft.EntityFrameworkCore;
-using eShop.Ordering.API.Data.EntityConfigurations;
+using eShop.Ordering.Data.EntityConfigurations;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
///
-/// Add migrations using the following command inside the 'Ordering.Infrastructure' project directory:
+/// Add migrations using the following command inside the 'Ordering.Data.Manager' project directory:
///
-/// dotnet ef migrations add --startup-project Ordering.API --context OrderingContext [migration-name]
+/// dotnet ef migrations add --context OrderingDbContext [migration-name]
///
public class OrderingDbContext(DbContextOptions options) : DbContext(options)
{
diff --git a/src/Ordering.API/Data/PaymentMethod.cs b/src/Ordering.Data/PaymentMethod.cs
similarity index 95%
rename from src/Ordering.API/Data/PaymentMethod.cs
rename to src/Ordering.Data/PaymentMethod.cs
index 70a3a5f..def6c7b 100644
--- a/src/Ordering.API/Data/PaymentMethod.cs
+++ b/src/Ordering.Data/PaymentMethod.cs
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public class PaymentMethod
{
diff --git a/src/Ordering.API/Data/ValueObject.cs b/src/Ordering.Data/ValueObject.cs
similarity index 96%
rename from src/Ordering.API/Data/ValueObject.cs
rename to src/Ordering.Data/ValueObject.cs
index 33714b7..1331d3b 100644
--- a/src/Ordering.API/Data/ValueObject.cs
+++ b/src/Ordering.Data/ValueObject.cs
@@ -1,4 +1,4 @@
-namespace eShop.Ordering.API.Data;
+namespace eShop.Ordering.Data;
public abstract class ValueObject
{
diff --git a/src/Shared/MigrateDbContextExtensions.cs b/src/Shared/MigrateDbContextExtensions.cs
index 85a3fea..1235318 100644
--- a/src/Shared/MigrateDbContextExtensions.cs
+++ b/src/Shared/MigrateDbContextExtensions.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace Microsoft.AspNetCore.Hosting;
@@ -18,7 +19,12 @@ public static IServiceCollection AddMigration(this IServiceCollection
// Enable migration tracing
services.AddOpenTelemetry().WithTracing(tracing => tracing.AddSource(ActivitySourceName));
- return services.AddHostedService(sp => new MigrationHostedService(sp, seeder));
+ services.AddSingleton(sp => new MigrationHostedService(sp, seeder));
+ services.AddHostedService(sp => sp.GetRequiredService>());
+ services.AddHealthChecks()
+ .AddCheck>(ActivitySourceName, null);
+
+ return services;
}
public static IServiceCollection AddMigration(this IServiceCollection services)
@@ -26,6 +32,7 @@ public static IServiceCollection AddMigration(this IService
where TDbSeeder : class, IDbSeeder
{
services.AddScoped, TDbSeeder>();
+
return services.AddMigration((context, sp) => sp.GetRequiredService>().SeedAsync(context));
}
@@ -77,14 +84,28 @@ private static async Task InvokeSeeder(Func(IServiceProvider serviceProvider, Func seeder)
: BackgroundService where TContext : DbContext
{
- public override Task StartAsync(CancellationToken cancellationToken)
+ protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
return serviceProvider.MigrateDbContextAsync(seeder);
}
+ }
- protected override Task ExecuteAsync(CancellationToken stoppingToken)
+ private class MigrationHealthCheck(MigrationHostedService hostedService) : IHealthCheck
+ where TContext : DbContext
+ {
+ public Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
- return Task.CompletedTask;
+ var task = hostedService.ExecuteTask;
+
+ var result = task switch
+ {
+ { IsCompletedSuccessfully: true } => HealthCheckResult.Healthy(),
+ { IsFaulted: true } => HealthCheckResult.Unhealthy(task.Exception?.InnerException?.Message, task.Exception),
+ { IsCanceled: true } => HealthCheckResult.Unhealthy("Database migration was canceled"),
+ _ => HealthCheckResult.Degraded("Database migration is still in progress")
+ };
+
+ return Task.FromResult(result);
}
}
}
diff --git a/src/eShop.AppHost/Program.cs b/src/eShop.AppHost/Program.cs
index 9a3b964..273d207 100644
--- a/src/eShop.AppHost/Program.cs
+++ b/src/eShop.AppHost/Program.cs
@@ -1,4 +1,6 @@
-var builder = DistributedApplication.CreateBuilder(args);
+using Projects;
+
+var builder = DistributedApplication.CreateBuilder(args);
// Databases
@@ -9,36 +11,44 @@
// Identity Providers
-var keycloak = builder.AddKeycloakContainer("idp", tag: "23.0")
+var idp = builder.AddKeycloakContainer("idp", tag: "23.0")
.ImportRealms("../Keycloak/data/import");
+// DB Manager Apps
+
+builder.AddProject("catalog-db-mgr")
+ .WithReference(catalogDb);
+
+builder.AddProject("ordering-db-mgr")
+ .WithReference(orderDb);
+
// API Apps
-var catalogApi = builder.AddProject("catalog-api")
+var catalogApi = builder.AddProject("catalog-api")
.WithReference(catalogDb);
-var basketApi = builder.AddProject("basket-api")
+var basketApi = builder.AddProject("basket-api")
.WithReference(basketStore)
- .WithReference(keycloak);
+ .WithReference(idp);
-var orderingApi = builder.AddProject("ordering-api")
+var orderingApi = builder.AddProject("ordering-api")
.WithReference(orderDb)
- .WithReference(keycloak);
+ .WithReference(idp);
// Apps
-var webApp = builder.AddProject("webapp")
+var webApp = builder.AddProject("webapp")
.WithReference(basketApi)
.WithReference(catalogApi)
.WithReference(orderingApi)
- .WithReference(keycloak)
+ .WithReference(idp)
// Force HTTPS profile for web app (required for OIDC operations)
.WithLaunchProfile("https");
// Inject the project URLs for Keycloak realm configuration
-keycloak.WithEnvironment("WEBAPP_HTTP", () => webApp.GetEndpoint("http").UriString);
-keycloak.WithEnvironment("WEBAPP_HTTPS", () => webApp.GetEndpoint("https").UriString);
-keycloak.WithEnvironment("ORDERINGAPI_HTTP", () => orderingApi.GetEndpoint("http").UriString);
+idp.WithEnvironment("WEBAPP_HTTP", () => webApp.GetEndpoint("http").UriString);
+idp.WithEnvironment("WEBAPP_HTTPS", () => webApp.GetEndpoint("https").UriString);
+idp.WithEnvironment("ORDERINGAPI_HTTP", () => orderingApi.GetEndpoint("http").UriString);
// Inject assigned URLs for Catalog API
catalogApi.WithEnvironment("CatalogOptions__PicBaseAddress", () => catalogApi.GetEndpoint("http").UriString);
diff --git a/src/eShop.AppHost/eShop.AppHost.csproj b/src/eShop.AppHost/eShop.AppHost.csproj
index a98edb0..29f144b 100644
--- a/src/eShop.AppHost/eShop.AppHost.csproj
+++ b/src/eShop.AppHost/eShop.AppHost.csproj
@@ -16,7 +16,9 @@
+
+
diff --git a/src/eShop.ServiceDefaults/HostingExtensions.cs b/src/eShop.ServiceDefaults/HostingExtensions.cs
index adc7df8..2cd88e4 100644
--- a/src/eShop.ServiceDefaults/HostingExtensions.cs
+++ b/src/eShop.ServiceDefaults/HostingExtensions.cs
@@ -13,7 +13,9 @@ public static partial class HostingExtensions
{
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
{
- builder.AddBasicServiceDefaults();
+ builder.AddDefaultHealthChecks();
+
+ builder.ConfigureOpenTelemetry();
builder.Services.AddServiceDiscovery();
@@ -29,22 +31,6 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
return builder;
}
- ///
- /// Adds the services except for making outgoing HTTP calls.
- ///
- ///
- /// This allows for things like Polly to be trimmed out of the app if it isn't used.
- ///
- public static IHostApplicationBuilder AddBasicServiceDefaults(this IHostApplicationBuilder builder)
- {
- // Default health checks assume the event bus and self health checks
- builder.AddDefaultHealthChecks();
-
- builder.ConfigureOpenTelemetry();
-
- return builder;
- }
-
public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{
builder.Logging.AddOpenTelemetry(o =>
@@ -97,12 +83,6 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli
return builder;
}
- private static MeterProviderBuilder AddBuiltInMeters(this MeterProviderBuilder meterProviderBuilder) =>
- meterProviderBuilder.AddMeter(
- "Microsoft.AspNetCore.Hosting",
- "Microsoft.AspNetCore.Server.Kestrel",
- "System.Net.Http");
-
public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder)
{
builder.Services.AddHealthChecks()
@@ -121,11 +101,17 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
app.MapHealthChecks("/health");
// Only health checks tagged with the "live" tag must pass for app to be considered alive
- app.MapHealthChecks("/liveness", new HealthCheckOptions
+ app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
return app;
}
+
+ private static MeterProviderBuilder AddBuiltInMeters(this MeterProviderBuilder meterProviderBuilder) =>
+ meterProviderBuilder.AddMeter(
+ "Microsoft.AspNetCore.Hosting",
+ "Microsoft.AspNetCore.Server.Kestrel",
+ "System.Net.Http");
}
diff --git a/src/eShop.ServiceDefaults/eShop.ServiceDefaults.csproj b/src/eShop.ServiceDefaults/eShop.ServiceDefaults.csproj
index dca2bf0..47c2054 100644
--- a/src/eShop.ServiceDefaults/eShop.ServiceDefaults.csproj
+++ b/src/eShop.ServiceDefaults/eShop.ServiceDefaults.csproj
@@ -1,8 +1,11 @@
+ Library
net8.0
+ enable
enable
+ true