modular-monolith-with-ddd
modular-monolith-with-ddd copied to clipboard
InMemoryEventBus Enhancement
Hi,
Can we change the data structure which is used to store subscribers (currently a List<HandlerSubscription>) to a more efficient data structure? This will avoid the linear time complexity of getting the right handlers for the published event. A dictionary will be a good choice.
var integrationEventHandlers = _handlers.Where(x => x.EventName == eventType.FullName).ToList();
Hi, @geekhybrid. In general you are right that it's more efficient to look up in Dictionary than in List. But:
- first of all there may be many handlers for an integration event so we can't use event name as a key in Dictionary
- using List in discussing code makes the code natural and easy to read
- integration events handlers collection won't have so many items to get perceptible profit in performance with Dictionary
Hi @geekhybrid , @AndreiGanichev
I think it can be a dictionary, I created PR. What do you think?
See https://github.com/kgrzybek/modular-monolith-with-ddd/pull/166