Browse Source
Add IgnoreEventSelectors to AbpDistributedEntityEventOptions for event filtering.
pull/22471/head
maliming
1 year ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
4 changed files with
20 additions and
7 deletions
-
framework/src/Volo.Abp.Ddd.Domain.Shared/Volo/Abp/Domain/Entities/Events/Distributed/AbpDistributedEntityEventOptions.cs
-
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbModule.cs
|
|
|
@ -4,11 +4,14 @@ public class AbpDistributedEntityEventOptions |
|
|
|
{ |
|
|
|
public IAutoEntityDistributedEventSelectorList AutoEventSelectors { get; } |
|
|
|
|
|
|
|
public IAutoEntityDistributedEventSelectorList IgnoreEventSelectors { get; } |
|
|
|
|
|
|
|
public EtoMappingDictionary EtoMappings { get; set; } |
|
|
|
|
|
|
|
public AbpDistributedEntityEventOptions() |
|
|
|
{ |
|
|
|
AutoEventSelectors = new AutoEntityDistributedEventSelectorList(); |
|
|
|
IgnoreEventSelectors = new AutoEntityDistributedEventSelectorList(); |
|
|
|
EtoMappings = new EtoMappingDictionary(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -68,13 +68,9 @@ public class EntityChangeEventHelper : IEntityChangeEventHelper, ITransientDepen |
|
|
|
|
|
|
|
private bool ShouldPublishDistributedEventForEntity(object entity) |
|
|
|
{ |
|
|
|
return DistributedEntityEventOptions |
|
|
|
.AutoEventSelectors |
|
|
|
.IsMatch( |
|
|
|
ProxyHelper |
|
|
|
.UnProxy(entity) |
|
|
|
.GetType() |
|
|
|
); |
|
|
|
var entityType = ProxyHelper.UnProxy(entity).GetType(); |
|
|
|
return !DistributedEntityEventOptions.IgnoreEventSelectors.IsMatch(entityType) && |
|
|
|
DistributedEntityEventOptions.AutoEventSelectors.IsMatch(entityType); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void PublishEntityUpdatedEvent(object entity) |
|
|
|
|
|
|
|
@ -2,6 +2,7 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Volo.Abp.Domain; |
|
|
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
|
|
|
using Volo.Abp.EntityFrameworkCore.DistributedEvents; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.Uow.EntityFrameworkCore; |
|
|
|
@ -28,5 +29,11 @@ public class AbpEntityFrameworkCoreModule : AbpModule |
|
|
|
context.Services.TryAddTransient(typeof(IDbContextProvider<>), typeof(UnitOfWorkDbContextProvider<>)); |
|
|
|
context.Services.AddTransient(typeof(IDbContextEventOutbox<>), typeof(DbContextEventOutbox<>)); |
|
|
|
context.Services.AddTransient(typeof(IDbContextEventInbox<>), typeof(DbContextEventInbox<>)); |
|
|
|
|
|
|
|
Configure<AbpDistributedEntityEventOptions>(options => |
|
|
|
{ |
|
|
|
options.IgnoreEventSelectors.Add<OutgoingEventRecord>(); |
|
|
|
options.IgnoreEventSelectors.Add<IncomingEventRecord>(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -4,6 +4,7 @@ using MongoDB.Bson; |
|
|
|
using MongoDB.Bson.Serialization; |
|
|
|
using MongoDB.Bson.Serialization.Serializers; |
|
|
|
using Volo.Abp.Domain; |
|
|
|
using Volo.Abp.Domain.Entities.Events.Distributed; |
|
|
|
using Volo.Abp.Domain.Repositories.MongoDB; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
using Volo.Abp.MongoDB.DependencyInjection; |
|
|
|
@ -48,5 +49,11 @@ public class AbpMongoDbModule : AbpModule |
|
|
|
typeof(IMongoDbContextEventInbox<>), |
|
|
|
typeof(MongoDbContextEventInbox<>) |
|
|
|
); |
|
|
|
|
|
|
|
Configure<AbpDistributedEntityEventOptions>(options => |
|
|
|
{ |
|
|
|
options.IgnoreEventSelectors.Add<OutgoingEventRecord>(); |
|
|
|
options.IgnoreEventSelectors.Add<IncomingEventRecord>(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|