Skip to content

Commit

Permalink
Changed the service lifetime of the event dispacher to scoped. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand authored Nov 19, 2022
1 parent 4a612d4 commit ab38fbf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Fluxera.Entity/DomainEvents/DomainEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DomainEventDispatcher(IServiceProvider serviceProvider)
}

/// <inheritdoc />
public async Task DispatchAsync(IDomainEvent domainEvent)
public virtual async Task DispatchAsync(IDomainEvent domainEvent)
{
Type eventType = domainEvent.GetType();
Type eventHandlerType = typeof(IDomainEventHandler<>).MakeGenericType(eventType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public DomainEventHandlerBuilder AddDomainEventHandlers(Type type)
}

/// <summary>
/// Adds the provided domain dispatcher service.
/// Adds the provided domain dispatcher service as scoped.
/// </summary>
/// <typeparam name="TDispatcher"></typeparam>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the domain events services.
/// Adds the domain events services. The domain events dispatcher is register as scoped.
/// </summary>
/// <param name="services"></param>
/// <param name="configureHandlers"></param>
Expand All @@ -24,7 +24,7 @@ public static IServiceCollection AddDomainEvents(this IServiceCollection service
Guard.Against.Null(configureHandlers);

// Register domain event dispatcher.
services.TryAddTransient<IDomainEventDispatcher, DomainEventDispatcher>();
services.AddDomainEventDispatcher<DomainEventDispatcher>();

// Configure the domain event handlers.
configureHandlers.Invoke(new DomainEventHandlerBuilder(services));
Expand All @@ -33,7 +33,7 @@ public static IServiceCollection AddDomainEvents(this IServiceCollection service
}

/// <summary>
/// Adds the provided domain dispatcher service.
/// Adds the provided domain dispatcher service as scoped.
/// </summary>
/// <typeparam name="TDispatcher"></typeparam>
/// <param name="services"></param>
Expand All @@ -42,7 +42,7 @@ public static IServiceCollection AddDomainEventDispatcher<TDispatcher>(this ISer
where TDispatcher : class, IDomainEventDispatcher
{
services.RemoveAll<IDomainEventDispatcher>();
services.AddTransient<IDomainEventDispatcher, TDispatcher>();
services.AddScoped<IDomainEventDispatcher, TDispatcher>();

return services;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Fluxera.Entity/PropertyAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Fluxera.Entity
// ReSharper disable AssignNullToNotNullAttribute
// ReSharper disable PossibleNullReferenceException

namespace Fluxera.Entity
{
using System;
using System.Collections.Concurrent;
Expand Down

0 comments on commit ab38fbf

Please sign in to comment.