Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Cortex.Mediator/DependencyInjection/MediatorOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Cortex.Mediator.Commands;
using Cortex.Mediator.Commands;
using Cortex.Mediator.Queries;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ public class MediatorOptions
internal List<Type> CommandBehaviors { get; } = new();
internal List<Type> QueryBehaviors { get; } = new();

public bool OnlyPublicClasses { get; set; } = true;

public MediatorOptions AddCommandPipelineBehavior<TBehavior>()
where TBehavior : ICommandPipelineBehavior<ICommand> // Add constraint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Cortex.Mediator.Commands;
using Cortex.Mediator.Commands;
using Cortex.Mediator.Infrastructure;
using Cortex.Mediator.Notifications;
using Cortex.Mediator.Queries;
Expand Down Expand Up @@ -27,36 +27,37 @@ 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;
}

private static void RegisterHandlers(
IServiceCollection services,
IEnumerable<Type> assemblyMarkerTypes)
IEnumerable<Type> 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());
}
Expand All @@ -76,7 +77,6 @@ private static void RegisterPipelineBehaviors(IServiceCollection services, Media
}
}


private static void AddUnitOfWork(this IServiceCollection services)
{
services.AddScoped<IUnitOfWork>(provider =>
Expand Down
4 changes: 4 additions & 0 deletions src/Cortex.Streams.Pulsar/PulsarSinkOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public PulsarSinkOperator(string serviceUrl, string topic, ISerializer<TInput> 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()
Expand Down