开源的轻量级本地事件总线类库
nuget | stats |
---|---|
services.AddLocalMessage(Assembly.GetExecutingAssembly());
public class HelloEvent: ILocalEvent
{
}
public class HelloEventHandler : ILocalEventHandler<HelloEvent>
{
public async Task HandleAsync(HelloEvent eventData, CancellationToken cancellationToken = default)
{
await Task.CompletedTask;
}
}
await eventBus.PublishAsync(new HelloEvent());
public class Ping : IRequest<Pong>
{
}
public class Pong
{
}
public class PingHandler : IRequestHandler<Ping, Pong>
{
public Task<Pong> HandleAsync(Ping eventData, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Pong());
}
}
var pongMessage = eventBus.SendAsync(ping);
public class WrappedEventData
{
}
public class WrappedEventHandler : ILocalEventHandler<LocalEventWrapper<WrappedEventData>>
{
public async Task HandleAsync(LocalEventWrapper<WrappedEventData> eventData, CancellationToken cancellationToken = default)
{
await Task.CompletedTask;
}
}
eventBus.SendAsync(new WrappedEventData());
MIT