Code re-factorings and formatting in EventBus projects
This commit is contained in:
parent
80eb943d78
commit
086302f5f1
@ -1,8 +1,4 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
|
||||||
{
|
{
|
||||||
|
using IntegrationEvent = Events.IntegrationEvent;
|
||||||
|
|
||||||
public interface IEventBus
|
public interface IEventBus
|
||||||
{
|
{
|
||||||
void Publish(IntegrationEvent @event);
|
void Publish(IntegrationEvent @event);
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Task = System.Threading.Tasks.Task;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions
|
||||||
{
|
{
|
||||||
|
using IntegrationEvent = Events.IntegrationEvent;
|
||||||
|
|
||||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||||
where TIntegrationEvent : IntegrationEvent
|
where TIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using DateTime = System.DateTime;
|
||||||
|
using Guid = System.Guid;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
|
||||||
{
|
{
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using static Microsoft.eShopOnContainers.BuildingBlocks.EventBus.InMemoryEventBusSubscriptionsManager;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||||
{
|
{
|
||||||
|
using static InMemoryEventBusSubscriptionsManager;
|
||||||
|
|
||||||
public interface IEventBusSubscriptionsManager
|
public interface IEventBusSubscriptionsManager
|
||||||
{
|
{
|
||||||
bool IsEmpty { get; }
|
bool IsEmpty { get; }
|
||||||
|
@ -3,8 +3,6 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
||||||
{
|
{
|
||||||
@ -28,9 +26,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
|||||||
|
|
||||||
public void AddDynamicSubscription<TH>(string eventName)
|
public void AddDynamicSubscription<TH>(string eventName)
|
||||||
where TH : IDynamicIntegrationEventHandler
|
where TH : IDynamicIntegrationEventHandler
|
||||||
{
|
=> DoAddSubscription(typeof(TH), eventName, isDynamic: true);
|
||||||
DoAddSubscription(typeof(TH), eventName, isDynamic: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddSubscription<T, TH>()
|
public void AddSubscription<T, TH>()
|
||||||
where T : IntegrationEvent
|
where T : IntegrationEvent
|
||||||
@ -103,10 +99,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<SubscriptionInfo> GetHandlersForEvent<T>() where T : IntegrationEvent
|
public IEnumerable<SubscriptionInfo> GetHandlersForEvent<T>() where T : IntegrationEvent
|
||||||
{
|
=> GetHandlersForEvent(GetEventKey<T>());
|
||||||
var key = GetEventKey<T>();
|
|
||||||
return GetHandlersForEvent(key);
|
|
||||||
}
|
|
||||||
public IEnumerable<SubscriptionInfo> GetHandlersForEvent(string eventName) => _handlers[eventName];
|
public IEnumerable<SubscriptionInfo> GetHandlersForEvent(string eventName) => _handlers[eventName];
|
||||||
|
|
||||||
private void RaiseOnEventRemoved(string eventName)
|
private void RaiseOnEventRemoved(string eventName)
|
||||||
@ -121,42 +114,24 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus
|
|||||||
|
|
||||||
private SubscriptionInfo FindDynamicSubscriptionToRemove<TH>(string eventName)
|
private SubscriptionInfo FindDynamicSubscriptionToRemove<TH>(string eventName)
|
||||||
where TH : IDynamicIntegrationEventHandler
|
where TH : IDynamicIntegrationEventHandler
|
||||||
{
|
=> DoFindSubscriptionToRemove(eventName, typeof(TH));
|
||||||
return DoFindSubscriptionToRemove(eventName, typeof(TH));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private SubscriptionInfo FindSubscriptionToRemove<T, TH>()
|
private SubscriptionInfo FindSubscriptionToRemove<T, TH>()
|
||||||
where T : IntegrationEvent
|
where T : IntegrationEvent
|
||||||
where TH : IIntegrationEventHandler<T>
|
where TH : IIntegrationEventHandler<T>
|
||||||
{
|
=> DoFindSubscriptionToRemove(GetEventKey<T>(), typeof(TH));
|
||||||
var eventName = GetEventKey<T>();
|
|
||||||
return DoFindSubscriptionToRemove(eventName, typeof(TH));
|
|
||||||
}
|
|
||||||
|
|
||||||
private SubscriptionInfo DoFindSubscriptionToRemove(string eventName, Type handlerType)
|
private SubscriptionInfo DoFindSubscriptionToRemove(string eventName, Type handlerType)
|
||||||
{
|
=> !HasSubscriptionsForEvent(eventName) ? null : _handlers[eventName].SingleOrDefault(s => s.HandlerType == handlerType);
|
||||||
if (!HasSubscriptionsForEvent(eventName))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _handlers[eventName].SingleOrDefault(s => s.HandlerType == handlerType);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasSubscriptionsForEvent<T>() where T : IntegrationEvent
|
public bool HasSubscriptionsForEvent<T>() where T : IntegrationEvent
|
||||||
{
|
=> HasSubscriptionsForEvent(GetEventKey<T>());
|
||||||
var key = GetEventKey<T>();
|
|
||||||
return HasSubscriptionsForEvent(key);
|
|
||||||
}
|
|
||||||
public bool HasSubscriptionsForEvent(string eventName) => _handlers.ContainsKey(eventName);
|
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.SingleOrDefault(t => t.Name == eventName);
|
||||||
|
|
||||||
public string GetEventKey<T>()
|
public string GetEventKey<T>()
|
||||||
{
|
=> typeof(T).Name;
|
||||||
return typeof(T).Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user