Domain Events with .NET - Events Dispatcher Executor

Introduction

You may remember my Domain Events with .NET post and library. I recently made some changes, and now, some more, of which I'll talk here.

I'm now introducing a new concept:

  • dispatcher executor is a class that is responsible for calling subscribers when invoked by a dispatcher

Events Dispatcher Executor

Essentially, it's a new interface/abstraction, IEventsDispatcherExecutor. This interface - or, rather, one implementation of it - is the actual responsible for calling a subscription inside the IEventsDispatcher implementation, so all existing implementations were modified to use it.

This allows, for example, a retry strategy. I included a simple one, which can be applied by using the WithRetries extension method:

builder.Services.AddDomainEventsFromAssembly(typeof(Program).Assembly)
    .WithRetries(3, TimeSpan.FromSeconds(3));

And this is it. In the case of any exception while invoking the subscription, the executor will retry a number of times, with some delay between them, until it either gives up (max retries reached) or succeeds.

There are other possibilities, of couse, so, if you want to register your own implementation, make sure you do that before calling AddDomainEvents:

builder.Services.AddSingleton<IEventsDispatcherExecutor, MyEventsDispatcherExecutor();
builder.Services.AddDomainEvents();

Conclusion

As always, hope you find this useful, and let me know your thoughts!

Source Code: https://github.com/rjperes/DomainEvents

Nuget: https://www.nuget.org/packages/NetDomainEvents

Comments

Popular posts from this blog

Domain Events with .NET

Domain Events with .NET - New Features

Named HttpClient Registrations