diff --git a/Source/EventFlow/EventFlowOptions.cs b/Source/EventFlow/EventFlowOptions.cs index 8231aefb7..01264a2a3 100644 --- a/Source/EventFlow/EventFlowOptions.cs +++ b/Source/EventFlow/EventFlowOptions.cs @@ -22,8 +22,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; using System.Reflection; using EventFlow.Aggregates; using EventFlow.Commands; @@ -53,11 +53,11 @@ namespace EventFlow { public class EventFlowOptions : IEventFlowOptions { - private readonly List _aggregateEventTypes = new List(); - private readonly List _sagaTypes = new List(); - private readonly List _commandTypes = new List(); + private readonly ConcurrentBag _aggregateEventTypes = new ConcurrentBag(); + private readonly ConcurrentBag _sagaTypes = new ConcurrentBag(); + private readonly ConcurrentBag _commandTypes = new ConcurrentBag(); private readonly EventFlowConfiguration _eventFlowConfiguration = new EventFlowConfiguration(); - private readonly List _jobTypes = new List + private readonly ConcurrentBag _jobTypes = new ConcurrentBag { typeof(PublishCommandJob), typeof(DispatchToAsynchronousEventSubscribersJob) @@ -73,8 +73,13 @@ private EventFlowOptions(IServiceCollection serviceCollection) RegisterDefaults(ServiceCollection); } - public static IEventFlowOptions New() => new EventFlowOptions(new ServiceCollection() - .AddLogging(b => b.AddConsole())); + public static IEventFlowOptions New() => + new EventFlowOptions( + new ServiceCollection() + .AddLogging(b => b + .SetMinimumLevel(LogLevel.Trace) + .AddConsole())); + public static IEventFlowOptions New(IServiceCollection serviceCollection) => new EventFlowOptions(serviceCollection); public IEventFlowOptions ConfigureOptimisticConcurrencyRetry(int retries, TimeSpan delayBeforeRetry) @@ -212,7 +217,7 @@ private void RegisterDefaults(IServiceCollection serviceCollection) serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); - serviceCollection.AddSingleton(r => new LoadedVersionedTypes( + serviceCollection.TryAddSingleton(r => new LoadedVersionedTypes( _jobTypes, _commandTypes, _aggregateEventTypes, diff --git a/Source/EventFlow/IEventFlowOptions.cs b/Source/EventFlow/IEventFlowOptions.cs index 318d41525..71905f3c6 100644 --- a/Source/EventFlow/IEventFlowOptions.cs +++ b/Source/EventFlow/IEventFlowOptions.cs @@ -32,6 +32,7 @@ public interface IEventFlowOptions { IServiceCollection ServiceCollection { get; } + IEventFlowOptions ConfigureThrowSubscriberExceptions(bool shouldThrow); IEventFlowOptions ConfigureOptimisticConcurrencyRetry(int retries, TimeSpan delayBeforeRetry); IEventFlowOptions Configure(Action configure); IEventFlowOptions AddEvents(IEnumerable aggregateEventTypes); diff --git a/Source/EventFlow/ReadStores/ReadModelFactory.cs b/Source/EventFlow/ReadStores/ReadModelFactory.cs index 53aea2d95..44d3f960a 100644 --- a/Source/EventFlow/ReadStores/ReadModelFactory.cs +++ b/Source/EventFlow/ReadStores/ReadModelFactory.cs @@ -66,7 +66,8 @@ public Task CreateAsync(string id, CancellationToken cancellationTok { _logger.LogTrace( "Creating new instance of read model type {ReadModelType} with ID {Id}", - typeof(TReadModel).PrettyPrint()); + typeof(TReadModel).PrettyPrint(), + id); } var readModel = (TReadModel) Activator.CreateInstance(typeof(TReadModel));