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
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ABCEGHJKLMNPRSTVXY
accessibilities
agrc
Alderaan
ALPN
Andi
apphost
appsettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Cleanup()
obj.Message = s_message;
obj.MessageType = s_type;
var result = obj.Message;
// No return GC collects it
// No return - GC collects it
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mocha/src/Examples/MediatorShowcase/Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public sealed class OrderShippedEmailHandler(ILogger<OrderShippedEmailHandler> l
{
public ValueTask HandleAsync(OrderShippedNotification notification, CancellationToken cancellationToken)
{
logger.LogInformation("[Email] Order {OrderId} shipped email sent to customer", notification.OrderId);
logger.LogInformation("[Email] Order {OrderId} shipped - email sent to customer", notification.OrderId);
return ValueTask.CompletedTask;
}
}
Expand All @@ -135,7 +135,7 @@ public sealed class OrderShippedAnalyticsHandler(ILogger<OrderShippedAnalyticsHa
{
public ValueTask HandleAsync(OrderShippedNotification notification, CancellationToken cancellationToken)
{
logger.LogInformation("[Analytics] Order {OrderId} shipped metrics recorded", notification.OrderId);
logger.LogInformation("[Analytics] Order {OrderId} shipped - metrics recorded", notification.OrderId);
return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Commands
// ──────────────────────────────────────────────────

// Void command no return value
// Void command - no return value
app.MapPost("/api/products", async (CreateProductRequest req, ISender sender) =>
{
await sender.SendAsync(new CreateProductCommand(req.Name, req.Price));
Expand Down
2 changes: 1 addition & 1 deletion src/Mocha/src/Examples/Transports/RabbitMQ/RabbitMQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
.Handler<OrderPlacedHandler>();

// Declare a quorum queue explicitly with durable flag.
// Quorum queues require durable=true non-durable quorum queues are not supported.
// Quorum queues require durable=true - non-durable quorum queues are not supported.
transport.DeclareQueue("orders.processing")
.Durable()
.AutoProvision()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Mocha.Mediator;
/// Extension methods for <see cref="MediatorMiddlewareFactoryContext"/> that allow middleware
/// factories to inspect the pipeline being compiled and decide whether to participate.
/// Returning <c>next</c> from a middleware factory when these checks fail eliminates the
/// middleware from that pipeline entirely zero runtime cost.
/// middleware from that pipeline entirely - zero runtime cost.
/// </summary>
public static class MediatorMiddlewareFactoryContextExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,22 @@ public interface IInMemoryMessagingTransportDescriptor : IMessagingTransportDesc
ReceiveMiddlewareConfiguration configuration,
string? before = null,
string? after = null);

/// <summary>
/// Claims a handler for this in-memory transport and returns a configurator for its receive endpoint.
/// The handler will be bound to a convention-named endpoint on this transport during initialization.
/// </summary>
/// <typeparam name="THandler">The handler type implementing <see cref="IHandler"/>.</typeparam>
/// <returns>A configurator that allows configuring the handler's receive endpoint.</returns>
IMessagingTransportHandlerDescriptor<IInMemoryReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler;

/// <summary>
/// Claims a consumer for this in-memory transport and returns a configurator for its receive endpoint.
/// The consumer will be bound to a convention-named endpoint on this transport during initialization.
/// </summary>
/// <typeparam name="TConsumer">The consumer type implementing <see cref="IConsumer"/>.</typeparam>
/// <returns>A configurator that allows configuring the consumer's receive endpoint.</returns>
IMessagingTransportConsumerDescriptor<IInMemoryReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public interface IInMemoryReceiveEndpointDescriptor : IReceiveEndpointDescriptor
/// <inheritdoc />
new IInMemoryReceiveEndpointDescriptor Handler<THandler>() where THandler : class, IHandler;

/// <inheritdoc />
new IInMemoryReceiveEndpointDescriptor Handler(Type handlerType);

/// <inheritdoc />
new IInMemoryReceiveEndpointDescriptor Consumer(Type consumerType);

/// <inheritdoc />
new IInMemoryReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private InMemoryDispatchEndpointDescriptor(IMessagingConfigurationContext contex
Configuration = new InMemoryDispatchEndpointConfiguration { Name = name, TopicName = name };
}

protected override InMemoryDispatchEndpointConfiguration Configuration { get; set; }
protected internal override InMemoryDispatchEndpointConfiguration Configuration { get; protected set; }

public IInMemoryDispatchEndpointDescriptor ToQueue(string name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public InMemoryMessagingTransportDescriptor(IMessagingSetupContext discoveryCont
Configuration = new InMemoryTransportConfiguration();
}

protected override InMemoryTransportConfiguration Configuration { get; set; }
protected internal override InMemoryTransportConfiguration Configuration { get; protected set; }

/// <inheritdoc />
public new IInMemoryMessagingTransportDescriptor ModifyOptions(Action<TransportOptions> configure)
Expand Down Expand Up @@ -108,6 +108,26 @@ public InMemoryMessagingTransportDescriptor(IMessagingSetupContext discoveryCont
return this;
}

/// <inheritdoc />
public IMessagingTransportHandlerDescriptor<IInMemoryReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler
{
var name = Context.Naming.GetReceiveEndpointName(typeof(THandler), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Handler(typeof(THandler));
return new MessagingTransportHandlerDescriptor<IInMemoryReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IMessagingTransportConsumerDescriptor<IInMemoryReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer
{
var name = Context.Naming.GetReceiveEndpointName(typeof(TConsumer), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Consumer(typeof(TConsumer));
return new MessagingTransportConsumerDescriptor<IInMemoryReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IInMemoryReceiveEndpointDescriptor Endpoint(string name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ internal InMemoryReceiveEndpointDescriptor(IMessagingConfigurationContext discov
return this;
}

public new IInMemoryReceiveEndpointDescriptor Handler(Type handlerType)
{
base.Handler(handlerType);

return this;
}

public new IInMemoryReceiveEndpointDescriptor Consumer(Type consumerType)
{
base.Consumer(consumerType);

return this;
}

public new IInMemoryReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer
{
base.Consumer<TConsumer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public InMemoryBindingDescriptor(IMessagingConfigurationContext context, string
}

/// <inheritdoc />
protected override InMemoryBindingConfiguration Configuration { get; set; }
protected internal override InMemoryBindingConfiguration Configuration { get; protected set; }

/// <inheritdoc />
public IInMemoryBindingDescriptor Source(string topicName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public InMemoryQueueDescriptor(IMessagingConfigurationContext context, string na
}

/// <inheritdoc />
protected override InMemoryQueueConfiguration Configuration { get; set; }
protected internal override InMemoryQueueConfiguration Configuration { get; protected set; }

/// <inheritdoc />
public IInMemoryQueueDescriptor Name(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public InMemoryTopicDescriptor(IMessagingConfigurationContext context, string na
}

/// <inheritdoc />
protected override InMemoryTopicConfiguration Configuration { get; set; }
protected internal override InMemoryTopicConfiguration Configuration { get; protected set; }

/// <inheritdoc />
public IInMemoryTopicDescriptor Name(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public interface IPostgresMessagingTransportDescriptor
ReceiveMiddlewareConfiguration configuration,
string? before = null,
string? after = null);

/// <summary>Claims a handler for this transport, creating a convention-named endpoint.</summary>
IMessagingTransportHandlerDescriptor<IPostgresReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler;

/// <summary>Claims a consumer for this transport, creating a convention-named endpoint.</summary>
IMessagingTransportConsumerDescriptor<IPostgresReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public interface IPostgresReceiveEndpointDescriptor : IReceiveEndpointDescriptor
/// <inheritdoc cref="IReceiveEndpointDescriptor{T}.Handler{THandler}"/>
new IPostgresReceiveEndpointDescriptor Handler<THandler>() where THandler : class, IHandler;

/// <inheritdoc cref="IReceiveEndpointDescriptor{T}.Handler(Type)"/>
new IPostgresReceiveEndpointDescriptor Handler(Type handlerType);

/// <inheritdoc cref="IReceiveEndpointDescriptor{T}.Consumer(Type)"/>
new IPostgresReceiveEndpointDescriptor Consumer(Type consumerType);

/// <inheritdoc cref="IReceiveEndpointDescriptor{T}.Consumer{TConsumer}"/>
new IPostgresReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ public PostgresMessagingTransportDescriptor(IMessagingSetupContext discoveryCont
return this;
}

/// <inheritdoc />
public IMessagingTransportHandlerDescriptor<IPostgresReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler
{
var name = Context.Naming.GetReceiveEndpointName(typeof(THandler), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Handler(typeof(THandler));
return new MessagingTransportHandlerDescriptor<IPostgresReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IMessagingTransportConsumerDescriptor<IPostgresReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer
{
var name = Context.Naming.GetReceiveEndpointName(typeof(TConsumer), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Consumer(typeof(TConsumer));
return new MessagingTransportConsumerDescriptor<IPostgresReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IPostgresMessagingTransportDescriptor AutoProvision(bool autoProvision = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ internal PostgresReceiveEndpointDescriptor(IMessagingConfigurationContext discov
return this;
}

/// <inheritdoc />
public new IPostgresReceiveEndpointDescriptor Handler(Type handlerType)
{
base.Handler(handlerType);

return this;
}

/// <inheritdoc />
public new IPostgresReceiveEndpointDescriptor Consumer(Type consumerType)
{
base.Consumer(consumerType);

return this;
}

/// <inheritdoc />
public new IPostgresReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ IRabbitMQMessagingTransportDescriptor ConnectionProvider(
ReceiveMiddlewareConfiguration configuration,
string? before = null,
string? after = null);

/// <summary>Claims a handler for this transport, creating a convention-named endpoint.</summary>
IMessagingTransportHandlerDescriptor<IRabbitMQReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler;

/// <summary>Claims a consumer for this transport, creating a convention-named endpoint.</summary>
IMessagingTransportConsumerDescriptor<IRabbitMQReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public interface IRabbitMQReceiveEndpointDescriptor : IReceiveEndpointDescriptor
/// <inheritdoc cref="IReceiveEndpointDescriptor{TConfiguration}.Handler{THandler}" />
new IRabbitMQReceiveEndpointDescriptor Handler<THandler>() where THandler : class, IHandler;

/// <inheritdoc cref="IReceiveEndpointDescriptor{TConfiguration}.Handler(Type)" />
new IRabbitMQReceiveEndpointDescriptor Handler(Type handlerType);

/// <inheritdoc cref="IReceiveEndpointDescriptor{TConfiguration}.Consumer(Type)" />
new IRabbitMQReceiveEndpointDescriptor Consumer(Type consumerType);

/// <inheritdoc cref="IReceiveEndpointDescriptor{TConfiguration}.Consumer{TConsumer}" />
new IRabbitMQReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ public RabbitMQMessagingTransportDescriptor(IMessagingSetupContext discoveryCont
return this;
}

/// <inheritdoc />
public IMessagingTransportHandlerDescriptor<IRabbitMQReceiveEndpointDescriptor> Handler<THandler>()
where THandler : class, IHandler
{
var name = Context.Naming.GetReceiveEndpointName(typeof(THandler), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Handler(typeof(THandler));
return new MessagingTransportHandlerDescriptor<IRabbitMQReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IMessagingTransportConsumerDescriptor<IRabbitMQReceiveEndpointDescriptor> Consumer<TConsumer>()
where TConsumer : class, IConsumer
{
var name = Context.Naming.GetReceiveEndpointName(typeof(TConsumer), ReceiveEndpointKind.Default);
var endpoint = Endpoint(name);
endpoint.Consumer(typeof(TConsumer));
return new MessagingTransportConsumerDescriptor<IRabbitMQReceiveEndpointDescriptor>(endpoint);
}

/// <inheritdoc />
public IRabbitMQMessagingTransportDescriptor AutoProvision(bool autoProvision = true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ private RabbitMQReceiveEndpointDescriptor(IMessagingConfigurationContext discove
return this;
}

public new IRabbitMQReceiveEndpointDescriptor Handler(Type handlerType)
{
base.Handler(handlerType);

return this;
}
Comment thread
PascalSenn marked this conversation as resolved.

public new IRabbitMQReceiveEndpointDescriptor Consumer(Type consumerType)
{
base.Consumer(consumerType);

return this;
}

public new IRabbitMQReceiveEndpointDescriptor Consumer<TConsumer>() where TConsumer : class, IConsumer
{
base.Consumer<TConsumer>();
Expand Down
1 change: 1 addition & 0 deletions src/Mocha/src/Mocha/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[assembly: InternalsVisibleTo("Mocha.EntityFrameworkCore")]
[assembly: InternalsVisibleTo("Mocha.Transport.RabbitMQ")]
[assembly: InternalsVisibleTo("Mocha.Transport.Postgres")]
[assembly: InternalsVisibleTo("Mocha.Transport.InMemory")]
[assembly: InternalsVisibleTo("Mocha.Tests")]
[assembly: InternalsVisibleTo("Mocha.Sagas.TestHelpers")]
[assembly: InternalsVisibleTo("Mocha.Sagas.Tests")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ public interface IReceiveEndpointDescriptor<out TConfiguration>
/// <returns>The descriptor instance for method chaining.</returns>
IReceiveEndpointDescriptor<TConfiguration> Handler<THandler>() where THandler : class, IHandler;

/// <summary>
/// Binds a handler to this receive endpoint by its runtime type.
/// </summary>
/// <param name="handlerType">The handler type to bind.</param>
/// <returns>The descriptor instance for method chaining.</returns>
IReceiveEndpointDescriptor<TConfiguration> Handler(Type handlerType);
Comment thread
PascalSenn marked this conversation as resolved.

/// <summary>
/// Binds a consumer to this receive endpoint by its runtime type.
/// </summary>
/// <param name="consumerType">The consumer type to bind.</param>
/// <returns>The descriptor instance for method chaining.</returns>
IReceiveEndpointDescriptor<TConfiguration> Consumer(Type consumerType);

/// <summary>
/// Binds a consumer to this receive endpoint, ensuring its messages are consumed on this
/// endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ public IReceiveEndpointDescriptor<T> Consumer<TConsumer>() where TConsumer : cla
return this;
}

/// <summary>
/// Binds a handler to this receive endpoint by its runtime type.
/// </summary>
/// <param name="handlerType">The handler type to bind.</param>
/// <returns>The descriptor instance for method chaining.</returns>
public IReceiveEndpointDescriptor<T> Handler(Type handlerType)
{
Configuration.ConsumerIdentities.Add(handlerType);
return this;
}

/// <summary>
/// Binds a consumer to this receive endpoint by its runtime type.
/// </summary>
/// <param name="consumerType">The consumer type to bind.</param>
/// <returns>The descriptor instance for method chaining.</returns>
public IReceiveEndpointDescriptor<T> Consumer(Type consumerType)
{
Configuration.ConsumerIdentities.Add(consumerType);
return this;
}

public IReceiveEndpointDescriptor<T> Kind(ReceiveEndpointKind kind)
{
Configuration.Kind = kind;
Expand Down
Loading
Loading