diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs index a201bb2..80601c5 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs @@ -2,6 +2,7 @@ using EasyMicroservices.Cores.AspEntityFrameworkCoreApi; using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.Cores.Database.Managers; +using EasyMicroservices.Cores.Relational.EntityFrameworkCore; using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Contexts; using EasyMicroservices.Cores.Tests.DatabaseLogics.Database.Entities; @@ -18,7 +19,7 @@ public static async Task Main(string[] args) app.Services.Builder(); app.Services.AddScoped((serviceProvider) => new UnitOfWork(serviceProvider).GetLongContractLogic()); app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); - app.Services.AddScoped(serviceProvider => new DatabaseBuilder()); + app.Services.AddScoped(); app.Services.AddSingleton(service => new WhiteLabelManager(service)); app.Services.AddSingleton((provider) => { @@ -31,11 +32,18 @@ public static async Task Main(string[] args) } } - public class DatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder + public class DatabaseBuilder : EntityFrameworkCoreDatabaseBuilder { - public void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + public DatabaseBuilder(IConfiguration configuration) : base(configuration) { - optionsBuilder.UseInMemoryDatabase("Test DB"); + } + + public override void OnConfiguring(DbContextOptionsBuilder optionsBuilder, string name) + { + if (name == "InMemoryDatabase") + optionsBuilder.UseInMemoryDatabase("Test DB"); + else + optionsBuilder.UseInMemoryDatabase("Test DB"); } } } diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 750b42a..b21819f 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index 5b63cae..6d4c7a6 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -17,11 +17,11 @@ - - - + + + - + diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs index 65c8f5c..c01569c 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs @@ -82,15 +82,6 @@ public static IServiceCollection Builder(this IServiceCollection servi return services; } - //static string GetUniqueIdentityFromHttpContext(HttpContext httpContext) - //{ - // httpContext.ThrowIfNull(nameof(httpContext)); - // var uniqueIdentity = httpContext.User.FindFirst(nameof(IUniqueIdentitySchema.UniqueIdentity)); - // if (uniqueIdentity == null || uniqueIdentity.Value.IsNullOrEmpty()) - // return UnitOfWork.DefaultUniqueIdentity; - // return uniqueIdentity.Value; - //} - /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj index 456ccc0..b2324a6 100644 --- a/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Clients/EasyMicroservices.Cores.Clients.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 7e1f9ff..930783b 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -17,10 +17,10 @@ - - - - + + + + diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index dbc3012..12f9da2 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EntityFrameworkCoreDatabaseBuilder.cs b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EntityFrameworkCoreDatabaseBuilder.cs new file mode 100644 index 0000000..0352738 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EntityFrameworkCoreDatabaseBuilder.cs @@ -0,0 +1,39 @@ +using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; + +namespace EasyMicroservices.Cores.Relational.EntityFrameworkCore; +/// +/// +/// +public abstract class EntityFrameworkCoreDatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder +{ + /// + /// + /// + protected readonly IConfiguration Configuration; + /// + /// + /// + /// + public EntityFrameworkCoreDatabaseBuilder(IConfiguration configuration) + { + Configuration = configuration; + } + + /// + /// + /// + /// + public void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + OnConfiguring(optionsBuilder, Configuration.GetSection("Database:ProviderName").Value); + } + + /// + /// + /// + /// + /// + public abstract void OnConfiguring(DbContextOptionsBuilder optionsBuilder, string name); +} diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj index 9f7cedb..4348965 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Tests/EasyMicroservices.Cores.Tests.csproj @@ -9,11 +9,11 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive