fix(backend): simplify Finbuckle namespace imports and register DB interceptors
- Use consolidated Finbuckle.MultiTenant namespace instead of separate imports - Switch TenantProvider to use untyped IMultiTenantContextAccessor (Finbuckle 9.x pattern) - Register TenantDbConnectionInterceptor and SaveChangesTenantInterceptor as singletons - Add interceptors to DbContext configuration for RLS tenant context support - Update evidence files for Task 7 and Task 8 verification
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using Finbuckle.MultiTenant.Abstractions;
|
||||
using Finbuckle.MultiTenant.Extensions;
|
||||
using Finbuckle.MultiTenant.AspNetCore.Extensions;
|
||||
using Finbuckle.MultiTenant;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -8,6 +6,7 @@ using WorkClub.Api.Auth;
|
||||
using WorkClub.Api.Middleware;
|
||||
using WorkClub.Application.Interfaces;
|
||||
using WorkClub.Infrastructure.Data;
|
||||
using WorkClub.Infrastructure.Data.Interceptors;
|
||||
using WorkClub.Infrastructure.Services;
|
||||
using WorkClub.Infrastructure.Seed;
|
||||
|
||||
@@ -27,6 +26,9 @@ builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddScoped<ITenantProvider, TenantProvider>();
|
||||
builder.Services.AddScoped<SeedDataService>();
|
||||
|
||||
builder.Services.AddSingleton<TenantDbConnectionInterceptor>();
|
||||
builder.Services.AddSingleton<SaveChangesTenantInterceptor>();
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddJwtBearer(options =>
|
||||
{
|
||||
@@ -50,8 +52,11 @@ builder.Services.AddAuthorizationBuilder()
|
||||
.AddPolicy("RequireMember", policy => policy.RequireRole("Admin", "Manager", "Member"))
|
||||
.AddPolicy("RequireViewer", policy => policy.RequireAuthenticatedUser());
|
||||
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
||||
builder.Services.AddDbContext<AppDbContext>((sp, options) =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))
|
||||
.AddInterceptors(
|
||||
sp.GetRequiredService<TenantDbConnectionInterceptor>(),
|
||||
sp.GetRequiredService<SaveChangesTenantInterceptor>()));
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
if (!string.IsNullOrEmpty(connectionString))
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="9.0.0" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="10.0.3" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.3" />
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Finbuckle.MultiTenant" Version="10.0.3" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant" Version="9.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace WorkClub.Infrastructure.Services;
|
||||
|
||||
public class TenantProvider : ITenantProvider
|
||||
{
|
||||
private readonly IMultiTenantContextAccessor<TenantInfo> _multiTenantContextAccessor;
|
||||
private readonly IMultiTenantContextAccessor _multiTenantContextAccessor;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public TenantProvider(
|
||||
IMultiTenantContextAccessor<TenantInfo> multiTenantContextAccessor,
|
||||
IMultiTenantContextAccessor multiTenantContextAccessor,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_multiTenantContextAccessor = multiTenantContextAccessor;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Finbuckle.MultiTenant" Version="10.0.3" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="10.0.3" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant" Version="9.0.0" />
|
||||
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
Reference in New Issue
Block a user