Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to new structure of core #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ProductEntity : ProductSchema, IIdSchema<long>
public long OrderId { get; set; }
public OrderEntity Order { get; set; }

public long? ProductId { get; set; }
public long? ParentId { get; set; }
public ProductEntity Parent { get; set; }

public ICollection<ProductEntity> Children { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.15" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<ItemGroup>
<PackageReference Include="EasyMicroservices.Payments.Stripe" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.45" />
<PackageReference Include="EasyMicroservices.Domain" Version="0.0.0.1" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.1.55" />
<PackageReference Include="EasyMicroservices.Domain" Version="0.0.0.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public AppUnitOfWork(IServiceProvider service) : base(service)

}

public IConfiguration GetConfiguration()
{
return _service.GetService<IConfiguration>();
}

public async Task<MessageContract<IPaymentProvider>> GetPayment()
{
var service = await GetReadableOf<ServiceEntity>().FirstOrDefaultAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using EasyMicroservices.Cores.Database.Interfaces;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace EasyMicroservices.PaymentsMicroservice
{
public class DatabaseBuilder : IEntityFrameworkCoreDatabaseBuilder
public class DatabaseBuilder : EntityFrameworkCoreDatabaseBuilder
{
readonly IConfiguration _config;
public DatabaseBuilder(IConfiguration config)
public DatabaseBuilder(IConfiguration configuration, IDatabaseWidgetManager widgetManager) : base(configuration, widgetManager)
{
_config = config;
}

public void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
public override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseInMemoryDatabase("PaymentDatabase");
//optionsBuilder.UseSqlServer(_config.GetConnectionString("local"));
var entity = GetEntity();
if (entity.IsSqlServer())
optionsBuilder.UseSqlServer(entity.ConnectionString);
else if (entity.IsInMemory())
optionsBuilder.UseInMemoryDatabase("Payments");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.15" />
</ItemGroup>

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

<ItemGroup>
<PackageReference Include="EasyMicroservices.Laboratory" Version="0.0.0.15" />
<PackageReference Include="EasyMicroservices.Laboratory" Version="0.0.0.16" />
<PackageReference Include="EasyMicroservices.Payments.VirtualServerForTests" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.PaymentsMicroservice.Clients" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests" Version="0.0.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PackageReference Include="EasyMicroservices.WhiteLabelsMicroservice.VirtualServerForTests" Version="0.0.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
static bool IsInitialized = false;

protected static PaymentsVirtualTestManager PaymentsVirtualTestManager { get; set; } = new PaymentsVirtualTestManager();
protected static WhiteLabelVirtualTestManager WhiteLabelVirtualTestManager { get; set; } = new WhiteLabelVirtualTestManager();
//protected static WhiteLabelVirtualTestManager WhiteLabelVirtualTestManager { get; set; } = new WhiteLabelVirtualTestManager();

static IServiceProvider service = null;
static async Task StartServer()
{
if (IsStarted)
return;
IsStarted = true;
if (await WhiteLabelVirtualTestManager.OnInitialize(WhiteLabelPort))
{
foreach (var item in WhiteLabelResource.GetResources(new PaymentContext(new DatabaseBuilder(null)), "Payments"))
{
WhiteLabelVirtualTestManager.AppendService(WhiteLabelPort, item.Key, item.Value);
}
}
//if (await WhiteLabelVirtualTestManager.OnInitialize(WhiteLabelPort))
//{
// foreach (var item in WhiteLabelResource.GetResources(new PaymentContext(new DatabaseBuilder(null)), "Payments"))
// {
// WhiteLabelVirtualTestManager.AppendService(WhiteLabelPort, item.Key, item.Value);
// }
//}

TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
Thread thread = new Thread(async () =>
Expand Down Expand Up @@ -70,7 +70,7 @@

protected static int PaymentComponentPort = 1061;
static int Port = 1047;
static int WhiteLabelPort = 1041;

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used

Check warning on line 73 in src/CSharp/EasyMicroservices.PaymentsMicroservice.Tests/TestBase.cs

View workflow job for this annotation

GitHub Actions / os-tests

The field 'TestBase.WhiteLabelPort' is assigned but its value is never used
static HttpClient HttpClient = new HttpClient();
public OrderPortalClient GetOrderPortalClient()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.15">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ public class Program
public static async Task Main(string[] args)
{
var app = CreateBuilder(args);
var build = await app.Build<PaymentContext>(true);
var build = await app.BuildWithUseCors<PaymentContext>(null, true);
build.MapControllers();
await build.RunAsync();
}

static WebApplicationBuilder CreateBuilder(string[] args)
{
var app = StartUpExtensions.Create<PaymentContext>(args);
app.Services.Builder<PaymentContext>();
app.Services.AddTransient<IAppUnitOfWork>((serviceProvider) => new AppUnitOfWork(serviceProvider));
app.Services.AddTransient(serviceProvider => new PaymentContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>()));
app.Services.Builder<PaymentContext>("Payments")
.UseDefaultSwaggerOptions();
app.Services.AddTransient<IEntityFrameworkCoreDatabaseBuilder, DatabaseBuilder>();
StartUpExtensions.AddWhiteLabel("Payments", "RootAddresses:WhiteLabel");
app.Services.AddScoped<IAppUnitOfWork>((serviceProvider) => new AppUnitOfWork(serviceProvider));
app.Services.AddTransient(serviceProvider => new PaymentContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>()));
return app;
}

public static async Task Run(string[] args, Action<IServiceCollection> use, Action<IServiceProvider> serviceProvider)
{
var app = CreateBuilder(args);
use?.Invoke(app.Services);
var build = await app.Build<PaymentContext>();
var build = await app.BuildWithUseCors<PaymentContext>(null, true);
build.MapControllers();
serviceProvider(build.Services);
await build.RunAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,45 @@
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"local": "Server=.;Database=Payments;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True"
"Databases": [
{
"Name": "Entity",
"ProviderName": "InMemory",
"ConnectionString": "Server=.;Database=Payments;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True"
}
],
"ServiceAddresses": [
{
"Name": "Authentication",
"Address": "http://localhost:1044",
"Databases": null
},
{
"Name": "WhiteLabel",
"Address": "http://localhost:1041",
"Databases": null
}
],
"Authorization": {
"IsUse": false,
"JWT": {
"Key": "VGhpc0lzGHGHGHlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=",
"Issuer": "https://github.com/easymicroservices",
"Audience": "easymicroservices",

"TokenExpireTimeInSeconds": 86400
},
"FullAccessPAT": "ownerpat"
},
"Swagger": {
"IsUse": true,
"SwaggerUI": {
"Endpoints": []
}
},
"RootAddresses": {
"WhiteLabel": "http://localhost:1041"
"PaymentAddresses": {
"CallbackUrl": "http://localhost:1047",
"RedirectToPortalUrl": "http://localhost:1047/api/OrderPortal/OpenPortal?portalKey={0}"
},
"Urls": "http://*:1047"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,45 @@
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"local": "Server=.;Database=Payments;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True"
"Databases": [
{
"Name": "Entity",
"ProviderName": "InMemory",
"ConnectionString": "Server=.;Database=Payments;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True"
}
],
"ServiceAddresses": [
{
"Name": "Authentication",
"Address": "http://localhost:1044",
"Databases": null
},
{
"Name": "WhiteLabel",
"Address": "http://localhost:1041",
"Databases": null
}
],
"Authorization": {
"IsUse": false,
"JWT": {
"Key": "VGhpc0lzGHGHGHlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=",
"Issuer": "https://github.com/easymicroservices",
"Audience": "easymicroservices",

"TokenExpireTimeInSeconds": 86400
},
"FullAccessPAT": "ownerpat"
},
"RootAddresses": {
"WhiteLabel": "http://localhost:1041"
"Swagger": {
"IsUse": true,
"SwaggerUI": {
"Endpoints": []
}
},
"PaymentAddresses": {
"CallbackUrl": "http://localhost:1047",
"RedirectToPortalUrl": "http://localhost:1047/api/OrderPortal/OpenPortal?portalKey={0}"
},
"Urls": "http://*:1047"
}
}
Loading