0
PerigisettiVenkateswaraRao created
- ABP Framework version: v8.2.1
- UI Type: Angular
- Database System: EF Core (MySQL)
- Tiered (for MVC) or Auth Server Separated (for Angular): Auth server separated angular
- Exception message and full stack trace:
- Steps to reproduce the issue:
I need to create a custom filter to filter my entity based on BranchId
. The BranchId
will be received as a List<long>
from the request headers or parameters. Here's the approach I followed:
Created
IBranchEntity
Interface:- Placed this interface in the
Domain.Shared
folder. - It includes a
BranchId
property, which I inherited in the relevant entity.
- Placed this interface in the
Defined
IBranchContext
Interface:Entity Framework Filtering Logic:
Service Registration:
Registered the
IBranchContext
in theHostModule.cs
under theConfigureServices
method as follows:context.Services.AddHttpContextAccessor(); context.Services.AddScoped<IBranchContext, BranchContext>();
Database Context Changes:
- Updated the
ClinicServiceDbContext
constructor to accept theIBranchContext
.private readonly IBranchContext _branchContext; public ClinicServiceDbContext( DbContextOptions<ClinicServiceDbContext> options, IBranchContext branchContext ) : base(options) { _branchContext = branchContext; } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.ConfigureClinicService(); builder.ConfigureBranchFilterForEntities(_branchContext); }
- Updated the
After implementing the above, the filter is correctly identifying entities with the BranchFilter
when the application is initially loaded. However, it is not being triggered for subsequent requests.