mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-06-30 10:33:43 +00:00
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using CleanArchitecture.Domain.Entities;
|
|
using CleanArchitecture.Shared.Events.Tenant;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
|
|
namespace CleanArchitecture.Domain.EventHandler;
|
|
|
|
public sealed class TenantEventHandler :
|
|
INotificationHandler<TenantCreatedEvent>,
|
|
INotificationHandler<TenantDeletedEvent>,
|
|
INotificationHandler<TenantUpdatedEvent>
|
|
{
|
|
private readonly IDistributedCache _distributedCache;
|
|
|
|
public TenantEventHandler(IDistributedCache distributedCache)
|
|
{
|
|
_distributedCache = distributedCache;
|
|
}
|
|
|
|
public Task Handle(TenantCreatedEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public async Task Handle(TenantDeletedEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
await _distributedCache.RemoveAsync(
|
|
CacheKeyGenerator.GetEntityCacheKey<Tenant>(notification.AggregateId),
|
|
cancellationToken);
|
|
}
|
|
|
|
public async Task Handle(TenantUpdatedEvent notification, CancellationToken cancellationToken)
|
|
{
|
|
await _distributedCache.RemoveAsync(
|
|
CacheKeyGenerator.GetEntityCacheKey<Tenant>(notification.AggregateId),
|
|
cancellationToken);
|
|
}
|
|
} |