diff --git a/src/Cortex.Mediator/DependencyInjection/MediatorOptions.cs b/src/Cortex.Mediator/DependencyInjection/MediatorOptions.cs index c724388..f8a69b3 100644 --- a/src/Cortex.Mediator/DependencyInjection/MediatorOptions.cs +++ b/src/Cortex.Mediator/DependencyInjection/MediatorOptions.cs @@ -1,4 +1,4 @@ -using Cortex.Mediator.Commands; +using Cortex.Mediator.Commands; using Cortex.Mediator.Queries; using System; using System.Collections.Generic; @@ -11,6 +11,8 @@ public class MediatorOptions internal List CommandBehaviors { get; } = new(); internal List QueryBehaviors { get; } = new(); + public bool OnlyPublicClasses { get; set; } = true; + public MediatorOptions AddCommandPipelineBehavior() where TBehavior : ICommandPipelineBehavior // Add constraint { diff --git a/src/Cortex.Mediator/DependencyInjection/ServiceCollectionExtensions.cs b/src/Cortex.Mediator/DependencyInjection/ServiceCollectionExtensions.cs index 5acf911..93dc221 100644 --- a/src/Cortex.Mediator/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Cortex.Mediator/DependencyInjection/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -using Cortex.Mediator.Commands; +using Cortex.Mediator.Commands; using Cortex.Mediator.Infrastructure; using Cortex.Mediator.Notifications; using Cortex.Mediator.Queries; @@ -27,7 +27,7 @@ public static IServiceCollection AddCortexMediator( services.AddValidatorsFromAssemblies(handlerAssemblyMarkerTypes.Select(t => t.Assembly)); services.AddUnitOfWork(); - RegisterHandlers(services, handlerAssemblyMarkerTypes); + RegisterHandlers(services, handlerAssemblyMarkerTypes, options); RegisterPipelineBehaviors(services, options); return services; @@ -35,28 +35,29 @@ public static IServiceCollection AddCortexMediator( private static void RegisterHandlers( IServiceCollection services, - IEnumerable assemblyMarkerTypes) + IEnumerable assemblyMarkerTypes, + MediatorOptions options) { var assemblies = assemblyMarkerTypes.Select(t => t.Assembly).ToArray(); services.Scan(scan => scan .FromAssemblies(assemblies) .AddClasses(classes => classes - .AssignableTo(typeof(ICommandHandler<>))) + .AssignableTo(typeof(ICommandHandler<>)), options.OnlyPublicClasses) .AsImplementedInterfaces() .WithScopedLifetime()); services.Scan(scan => scan .FromAssemblies(assemblies) .AddClasses(classes => classes - .AssignableTo(typeof(IQueryHandler<,>))) + .AssignableTo(typeof(IQueryHandler<,>)), options.OnlyPublicClasses) .AsImplementedInterfaces() .WithScopedLifetime()); services.Scan(scan => scan .FromAssemblies(assemblies) .AddClasses(classes => classes - .AssignableTo(typeof(INotificationHandler<>))) + .AssignableTo(typeof(INotificationHandler<>)), options.OnlyPublicClasses) .AsImplementedInterfaces() .WithScopedLifetime()); } @@ -76,7 +77,6 @@ private static void RegisterPipelineBehaviors(IServiceCollection services, Media } } - private static void AddUnitOfWork(this IServiceCollection services) { services.AddScoped(provider => diff --git a/src/Cortex.Streams.Pulsar/PulsarSinkOperator.cs b/src/Cortex.Streams.Pulsar/PulsarSinkOperator.cs index f3fa43e..a33bf9e 100644 --- a/src/Cortex.Streams.Pulsar/PulsarSinkOperator.cs +++ b/src/Cortex.Streams.Pulsar/PulsarSinkOperator.cs @@ -28,6 +28,10 @@ public PulsarSinkOperator(string serviceUrl, string topic, ISerializer s _client = PulsarClient.Builder() .ServiceUrl(new Uri(_serviceUrl)) .Build(); + + // BUG #103 Start PulsarSink Operator when Sink is initialized + // Pulsar Producer doesnot start when the production happens, we have to start the Producer when it is initialized. + Start(); } public void Start()