Replies: 1 comment 4 replies
-
|
Hi there! Thanks for trying out LiteBus. You actually don't need a generic Here is how you can achieve your goal and why this design is chosen over the MediatR style. 1. The Solution: Polymorphic DispatchIn LiteBus, handler interfaces are contravariant (defined as If you want a "Global" pipeline that runs for every command, you have two ways to define it. Option A: The Non-Generic ShortcutYou can implement the non-generic using LiteBus.Commands.Abstractions;
// This runs for ALL commands in the system.
public class GlobalLoggingPreHandler : ICommandPreHandler
{
private readonly ILogger<GlobalLoggingPreHandler> _logger;
public GlobalLoggingPreHandler(ILogger<GlobalLoggingPreHandler> logger)
{
_logger = logger;
}
public Task PreHandleAsync(ICommand command, CancellationToken cancellationToken = default)
{
_logger.LogInformation("Global PreHandler executing for: {CommandType}", command.GetType().Name);
return Task.CompletedTask;
}
}Option B: The Generic Base Type (Polymorphic)You can also explicitly implement // This is functionally equivalent to Option A.
// It demonstrates that you can target any base type or interface.
public class GlobalLoggingPreHandler : ICommandPreHandler<ICommand>
{
public Task PreHandleAsync(ICommand command, CancellationToken cancellationToken = default)
{
// Logic here...
return Task.CompletedTask;
}
}2. Why no
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi People ...
I'm starting to use Litebus; it's a very good package, but when implementing it in my project, I noticed that it doesn't have a generic CommandPreHandler for TRequest and TResponse.
Currently, we don't have a way to implement a generic pipeline of that type.
Do you have plans to implement either of these types ?
Beta Was this translation helpful? Give feedback.
All reactions