-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tratamento para eventos (Apenas para rastreamento) #48
Comments
Olá @alesimoes, Gostaria de confirmar o bug e a sugestão sugerida: Eu entendi que ao não configurar um Handler para um evento o mediator lança uma exception. Essa exception seria A sugestão seria:
Seria isso? |
Olá @ivanpaulovich , Acredito que as duas formas que você apresentou são válidas. |
Hey @alesimoes, O que voce acha dessa implementação? c3c58aa#diff-14cb423500372d924cabf8d8f8cc87abR159-R182
Essa abordagem resolveria a sua implementação? |
@ivanpaulovich , Excelente solução Ivan. |
Olá @alesimoes, Estou chegando num design final, implementei duas formas de identificar que uma mensagem não chegou em uma pipeline: Opção 01: [Fact]
public void Publish_CallsPipelineNotFound_WhenHandlerIsNotSetup()
{
var services = new ServiceCollection();
// Mediator Without the Handler for PingRequest.
services.AddFluentMediator(builder => { });
var provider = services.BuildServiceProvider();
var mediator = provider.GetRequiredService<IMediator>();
bool myCustomPipelineNotFoundHandlerWasCalled = false;
// This is handler is called for every message without a destination pipeline.
mediator.PipelineNotFound += (object sender, PipelineNotFoundEventArgs e) => {
myCustomPipelineNotFoundHandlerWasCalled = true;
};
var cts = new CancellationTokenSource();
var ping = new PingRequest("Cancellable Async Ping");
// Should run without throwing exceptions
mediator.Publish(ping);
// The method was called :)
Assert.True(myCustomPipelineNotFoundHandlerWasCalled);
} Opção 02: // Add a Mediator derivative class
public class MyCustomMediator : Mediator
{
public bool MyCustomPipelineNotFoundHandlerWasCalled = false;
public MyCustomMediator(GetService getService, IPipelineProvider pipelines) : base(getService, pipelines)
{
}
protected override void OnPipelineNotFound(PipelineNotFoundEventArgs e)
{
MyCustomPipelineNotFoundHandlerWasCalled = true;
//Do something before raising the event
base.OnPipelineNotFound(e);
//Do something after raising the event
}
}
// Then you can run this:
[Fact]
public void Publish_CallsCustomPipelineNotFound_WhenHandlerIsNotSetup()
{
var services = new ServiceCollection();
// Mediator Without the Handler for PingRequest.
services.AddFluentMediator<MyCustomMediator>(builder => { });
var provider = services.BuildServiceProvider();
var mediator = (MyCustomMediator)provider.GetRequiredService<IMediator>();
var cts = new CancellationTokenSource();
var ping = new PingRequest("Cancellable Async Ping");
// Should run without throwing exceptions
mediator.Publish(ping);
// The method was called :)
Assert.True(mediator.MyCustomPipelineNotFoundHandlerWasCalled);
} Essas mudanças vão para a versão 0.4.7. |
Em primeira mão, publicado aqui: |
Opa, valeu @ivanpaulovich ! |
Ivan, blz?
Conforme conversamos.
Estou usando o FluentMediator para publicar os eventos de domínio.
No meu BUS eu uso o fluentMediator e ele publica o evento no mediator para o mediator executar a function associada.
Até ai ok.
Porém se o tratamento do evento não for registrado no FluentMediator ele levanta null Exception.
The text was updated successfully, but these errors were encountered: