store event type with event name
Since event name might be different from class name, store it with event name
This commit is contained in:
parent
08e28f24e9
commit
9086bad6f1
@ -11,14 +11,14 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
|
||||
|
||||
private readonly Dictionary<string, List<SubscriptionInfo>> _handlers;
|
||||
private readonly List<Type> _eventTypes;
|
||||
private readonly Dictionary<string, Type> _eventTypes;
|
||||
|
||||
public event EventHandler<string> OnEventRemoved;
|
||||
|
||||
public InMemoryEventBusSubscriptionsManager()
|
||||
{
|
||||
_handlers = new Dictionary<string, List<SubscriptionInfo>>();
|
||||
_eventTypes = new List<Type>();
|
||||
_eventTypes = new Dictionary<string, Type>();
|
||||
}
|
||||
|
||||
public bool IsEmpty => !_handlers.Keys.Any();
|
||||
@ -38,9 +38,9 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
|
||||
DoAddSubscription(typeof(TH), eventName, isDynamic: false);
|
||||
|
||||
if (!_eventTypes.Contains(typeof(T)))
|
||||
if (!_eventTypes.ContainsKey(eventName))
|
||||
{
|
||||
_eventTypes.Add(typeof(T));
|
||||
_eventTypes.Add(eventName, typeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,10 +94,9 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
if (!_handlers[eventName].Any())
|
||||
{
|
||||
_handlers.Remove(eventName);
|
||||
var eventType = _eventTypes.SingleOrDefault(e => e.Name == eventName);
|
||||
if (eventType != null)
|
||||
if (_eventTypes.ContainsKey(eventName))
|
||||
{
|
||||
_eventTypes.Remove(eventType);
|
||||
_eventTypes.Remove(eventName);
|
||||
}
|
||||
RaiseOnEventRemoved(eventName);
|
||||
}
|
||||
@ -152,7 +151,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||
}
|
||||
public bool HasSubscriptionsForEvent(string eventName) => _handlers.ContainsKey(eventName);
|
||||
|
||||
public Type GetEventTypeByName(string eventName) => _eventTypes.SingleOrDefault(t => t.Name == eventName);
|
||||
public Type GetEventTypeByName(string eventName) => _eventTypes.ContainsKey(eventName) ? _eventTypes[eventName] : default;
|
||||
|
||||
public string GetEventKey<T>()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user