init
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DouyinApi.EventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态集成事件处理程序
|
||||
/// 接口
|
||||
/// </summary>
|
||||
public interface IDynamicIntegrationEventHandler
|
||||
{
|
||||
Task Handle(dynamic eventData);
|
||||
}
|
||||
}
|
||||
49
DouyinApi.EventBus/Eventbus/IEventBus.cs
Normal file
49
DouyinApi.EventBus/Eventbus/IEventBus.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace DouyinApi.EventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件总线
|
||||
/// 接口
|
||||
/// </summary>
|
||||
public interface IEventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 发布
|
||||
/// </summary>
|
||||
/// <param name="event">事件模型</param>
|
||||
void Publish(IntegrationEvent @event);
|
||||
|
||||
/// <summary>
|
||||
/// 订阅
|
||||
/// </summary>
|
||||
/// <typeparam name="T">约束:事件模型</typeparam>
|
||||
/// <typeparam name="TH">约束:事件处理器<事件模型></typeparam>
|
||||
void Subscribe<T, TH>()
|
||||
where T : IntegrationEvent
|
||||
where TH : IIntegrationEventHandler<T>;
|
||||
|
||||
/// <summary>
|
||||
/// 取消订阅
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TH"></typeparam>
|
||||
void Unsubscribe<T, TH>()
|
||||
where TH : IIntegrationEventHandler<T>
|
||||
where T : IntegrationEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 动态订阅
|
||||
/// </summary>
|
||||
/// <typeparam name="TH">约束:事件处理器</typeparam>
|
||||
/// <param name="eventName"></param>
|
||||
void SubscribeDynamic<TH>(string eventName)
|
||||
where TH : IDynamicIntegrationEventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 动态取消订阅
|
||||
/// </summary>
|
||||
/// <typeparam name="TH"></typeparam>
|
||||
/// <param name="eventName"></param>
|
||||
void UnsubscribeDynamic<TH>(string eventName)
|
||||
where TH : IDynamicIntegrationEventHandler;
|
||||
}
|
||||
}
|
||||
36
DouyinApi.EventBus/Eventbus/IEventBusSubscriptionsManager.cs
Normal file
36
DouyinApi.EventBus/Eventbus/IEventBusSubscriptionsManager.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DouyinApi.EventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件总线订阅管理器
|
||||
/// 接口
|
||||
/// </summary>
|
||||
public interface IEventBusSubscriptionsManager
|
||||
{
|
||||
bool IsEmpty { get; }
|
||||
event EventHandler<string> OnEventRemoved;
|
||||
void AddDynamicSubscription<TH>(string eventName)
|
||||
where TH : IDynamicIntegrationEventHandler;
|
||||
|
||||
void AddSubscription<T, TH>()
|
||||
where T : IntegrationEvent
|
||||
where TH : IIntegrationEventHandler<T>;
|
||||
|
||||
void RemoveSubscription<T, TH>()
|
||||
where TH : IIntegrationEventHandler<T>
|
||||
where T : IntegrationEvent;
|
||||
void RemoveDynamicSubscription<TH>(string eventName)
|
||||
where TH : IDynamicIntegrationEventHandler;
|
||||
|
||||
bool HasSubscriptionsForEvent<T>() where T : IntegrationEvent;
|
||||
bool HasSubscriptionsForEvent(string eventName);
|
||||
Type GetEventTypeByName(string eventName);
|
||||
void Clear();
|
||||
IEnumerable<SubscriptionInfo> GetHandlersForEvent<T>() where T : IntegrationEvent;
|
||||
IEnumerable<SubscriptionInfo> GetHandlersForEvent(string eventName);
|
||||
string GetEventKey<T>();
|
||||
}
|
||||
|
||||
}
|
||||
23
DouyinApi.EventBus/Eventbus/IIntegrationEventHandler.cs
Normal file
23
DouyinApi.EventBus/Eventbus/IIntegrationEventHandler.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DouyinApi.EventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 集成事件处理程序
|
||||
/// 泛型接口
|
||||
/// </summary>
|
||||
/// <typeparam name="TIntegrationEvent"></typeparam>
|
||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||
where TIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
Task Handle(TIntegrationEvent @event);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 集成事件处理程序
|
||||
/// 基 接口
|
||||
/// </summary>
|
||||
public interface IIntegrationEventHandler
|
||||
{
|
||||
}
|
||||
}
|
||||
31
DouyinApi.EventBus/Eventbus/IntegrationEvent.cs
Normal file
31
DouyinApi.EventBus/Eventbus/IntegrationEvent.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace DouyinApi.EventBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件模型
|
||||
/// 基类
|
||||
/// </summary>
|
||||
public class IntegrationEvent
|
||||
{
|
||||
public IntegrationEvent()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreationDate = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public IntegrationEvent(Guid id, DateTime createDate)
|
||||
{
|
||||
Id = id;
|
||||
CreationDate = createDate;
|
||||
}
|
||||
|
||||
[JsonProperty]
|
||||
public Guid Id { get; private set; }
|
||||
|
||||
[JsonProperty]
|
||||
public DateTime CreationDate { get; private set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user