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