Skip to content

Commit

Permalink
Support for EntityFrameworkCoreDatabaseBuilder for use database in ap…
Browse files Browse the repository at this point in the history
…p setting
  • Loading branch information
Ali-YousefiTelori committed Dec 16, 2023
1 parent 17d9332 commit f764e97
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 29 deletions.
16 changes: 12 additions & 4 deletions src/CSharp/EasyMicroservices.Cores.AspCore.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +19,7 @@ public static async Task Main(string[] args)
app.Services.Builder<MyTestContext>();
app.Services.AddScoped((serviceProvider) => new UnitOfWork(serviceProvider).GetLongContractLogic<UserEntity, UserEntity, UserEntity, UserEntity>());
app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>()));
app.Services.AddScoped<IEntityFrameworkCoreDatabaseBuilder>(serviceProvider => new DatabaseBuilder());
app.Services.AddScoped<IEntityFrameworkCoreDatabaseBuilder, DatabaseBuilder>();
app.Services.AddSingleton(service => new WhiteLabelManager(service));
app.Services.AddSingleton<IUniqueIdentityManager, DefaultUniqueIdentityManager>((provider) =>
{
Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.AuthenticationsMicroservice.Clients" Version="0.0.0.17" />
<PackageReference Include="EasyMicroservices.AuthenticationsMicroservice.Clients" Version="*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.8" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="*" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="*" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="*" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.Clients" Version="0.0.0.11" />
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.Clients" Version="*" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ public static IServiceCollection Builder<TContext>(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;
//}

/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Database" Version="0.0.0.17" />
<PackageReference Include="EasyMicroservices.Mapper" Version="0.0.0.5" />
<PackageReference Include="EasyMicroservices.ServiceContracts" Version="0.0.0.21" />
<PackageReference Include="EasyMicroservices.Utilities" Version="0.0.0.13" />
<PackageReference Include="EasyMicroservices.Database" Version="*" />
<PackageReference Include="EasyMicroservices.Mapper" Version="*" />
<PackageReference Include="EasyMicroservices.ServiceContracts" Version="*" />
<PackageReference Include="EasyMicroservices.Utilities" Version="*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Database.EntityFrameworkCore" Version="0.0.0.17" />
<PackageReference Include="EasyMicroservices.Database.EntityFrameworkCore" Version="*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace EasyMicroservices.Cores.Relational.EntityFrameworkCore;
/// <summary>
///
/// </summary>
public abstract class EntityFrameworkCoreDatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder
{
/// <summary>
///
/// </summary>
protected readonly IConfiguration Configuration;
/// <summary>
///
/// </summary>
/// <param name="configuration"></param>
public EntityFrameworkCoreDatabaseBuilder(IConfiguration configuration)
{
Configuration = configuration;
}

/// <summary>
///
/// </summary>
/// <param name="optionsBuilder"></param>
public void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
OnConfiguring(optionsBuilder, Configuration.GetSection("Database:ProviderName").Value);
}

/// <summary>
///
/// </summary>
/// <param name="optionsBuilder"></param>
/// <param name="name"></param>
public abstract void OnConfiguring(DbContextOptionsBuilder optionsBuilder, string name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Laboratory" Version="0.0.0.15" />
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.8" />
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.9" />
<PackageReference Include="EasyMicroservices.Laboratory" Version="*" />
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="*" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="*" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="*" />
<PackageReference Include="EasyMicroservices.Tests" Version="*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit f764e97

Please sign in to comment.