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))
|
||||
|
||||
Reference in New Issue
Block a user