在 Aspire 中集成 PostgreSQL 数据库
This commit is contained in:
1 parent
ade2f40524
commit
9e6b5be92c
23 files changed
+44
-42
No files matched your search
@@ -5,9 +5,9 @@ namespace HelloShop.OrderingService.Constants
|
||||
{
|
||||
public class DbConstants
|
||||
{
|
||||
public const string MasterConnectionStringName = "OrderingDatabaseMaster";
|
||||
public const string MasterConnectionStringName = "orderingdb";
|
||||
|
||||
public const string SlaveConnectionStringName = "OrderingDatabaseSlave";
|
||||
public const string SlaveConnectionStringName = "orderingdb";
|
||||
|
||||
public const string MigrationsHistoryTableName = "migrations_history";
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using HelloShop.ServiceDefaults.DistributedEvents.DaprBuildingBlocks;
|
||||
using HelloShop.ServiceDefaults.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
@@ -34,9 +35,9 @@ namespace HelloShop.OrderingService.Extensions
|
||||
|
||||
builder.Services.AddDataSeedingProviders();
|
||||
|
||||
builder.Services.AddDbContext<OrderingServiceDbContext>(options =>
|
||||
builder.AddNpgsqlDbContext<OrderingServiceDbContext>(connectionName: DbConstants.MasterConnectionStringName, configureDbContextOptions: options =>
|
||||
{
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName), x => x.MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName));
|
||||
new NpgsqlDbContextOptionsBuilder(options).MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName);
|
||||
options.UseSnakeCaseNamingConvention();
|
||||
});
|
||||
|
||||
|
||||
@@ -8,14 +8,13 @@
|
||||
<ProjectReference Include="..\HelloShop.ServiceDefaults\HelloShop.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
<PackageReference Include="EFCore.NamingConventions" />
|
||||
<PackageReference Include="MediatR" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HelloShop.OrderingService.Workers
|
||||
{
|
||||
public class GracePeriodWorker(IServiceScopeFactory serviceScopeFactory, ILogger<GracePeriodWorker> logger,TimeProvider timeProvider) : BackgroundService
|
||||
public class GracePeriodWorker(IServiceScopeFactory serviceScopeFactory, ILogger<GracePeriodWorker> logger, TimeProvider timeProvider) : BackgroundService
|
||||
{
|
||||
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
@@ -5,9 +5,5 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres",
|
||||
"OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres"
|
||||
}
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in new issue
Block a user