diff --git a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs index 11b15b1..0225cfc 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs @@ -16,7 +16,7 @@ public static async Task Main(string[] args) app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService())); app.Services.AddScoped(serviceProvider => new DatabaseBuilder()); - var build = app.Build(); + var build = await app.Build(); build.MapControllers(); build.Run(); } diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj index d911541..39012bc 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/EasyMicroservices.Cores.AspEntityFrameworkCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.8 + 0.0.0.9 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet,aspcore,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs index 3bb94bf..21fc411 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/StartUpExtensions.cs @@ -108,7 +108,7 @@ public static async Task Build(this IApplicationBuilder app) var dbbuilder = new DatabaseCreator(); using var context = scope.ServiceProvider.GetRequiredService(); dbbuilder.Initialize(context); - var uow = scope.ServiceProvider.GetRequiredService() as UnitOfWork; + using var uow = scope.ServiceProvider.GetRequiredService() as UnitOfWork; await uow.Initialize("TextExample", "http://localhost:6041", typeof(TContext)).ConfigureAwait(false); } var build = app.Build(); @@ -121,7 +121,7 @@ public static async Task Build(this IApplicationBuilder app) /// /// /// - public static WebApplication Build(this WebApplicationBuilder app) + public static async Task Build(this WebApplicationBuilder app) where TContext : RelationalCoreContext { var build = app.Build(); @@ -139,6 +139,8 @@ public static WebApplication Build(this WebApplicationBuilder app) var dbbuilder = new DatabaseCreator(); using var context = scope.ServiceProvider.GetRequiredService(); dbbuilder.Initialize(context); + using var uow = scope.ServiceProvider.GetRequiredService() as UnitOfWork; + await uow.Initialize("TextExample", "http://localhost:6041", typeof(TContext)).ConfigureAwait(false); } return build; } diff --git a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs index cce8e8c..561820f 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspEntityFrameworkCoreApi/UnitOfWork.cs @@ -50,7 +50,7 @@ T AddDisposable(T data) /// /// /// - public IDatabase GetDatabase() + public virtual IDatabase GetDatabase() { var context = _service.GetService(); if (context == null) @@ -224,7 +224,7 @@ public virtual IEasyReadableQueryableAsync GetReadableQueryable /// /// - public IDatabase GetDatabase() + public virtual IDatabase GetDatabase() where TContext : RelationalCoreContext { var context = _service.GetService(); @@ -239,9 +239,12 @@ public IDatabase GetDatabase() /// /// /// - public IMapperProvider GetMapper() + public virtual IMapperProvider GetMapper() { - var mapper = new CompileTimeMapperProvider(new SerializerMapperProvider(new NewtonsoftJsonProvider())); + var mapper = new CompileTimeMapperProvider(new SerializerMapperProvider(new NewtonsoftJsonProvider(new Newtonsoft.Json.JsonSerializerSettings() + { + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + }))); if (MapperTypeAssembly != null) { foreach (var type in MapperTypeAssembly.Assembly.GetTypes()) @@ -274,7 +277,7 @@ public IMapperProvider GetMapper() /// /// /// - public IUniqueIdentityManager GetUniqueIdentityManager() + public virtual IUniqueIdentityManager GetUniqueIdentityManager() { if (UniqueIdentityManager == null) UniqueIdentityManager = new DefaultUniqueIdentityManager(DefaultUniqueIdentity, MicroserviceId); @@ -288,7 +291,7 @@ public IUniqueIdentityManager GetUniqueIdentityManager() /// /// /// - public Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes) + public virtual Task Initialize(string microserviceName, string whiteLableRoute, params Type[] dbContextTypes) { return new WhiteLabelManager(_service).Initialize(microserviceName, whiteLableRoute, dbContextTypes); } @@ -297,7 +300,7 @@ public Task Initialize(string microserviceName, string whiteLableRoute, params T /// /// /// - public void Dispose() + public virtual void Dispose() { foreach (var item in Disposables) { @@ -312,7 +315,7 @@ public void Dispose() /// /// /// - public async ValueTask DisposeAsync() + public virtual async ValueTask DisposeAsync() { foreach (var item in Disposables) {