Skip to content

Commit 7e88c8a

Browse files
committed
feat: 新增 事件总线 模块
1 parent 566e3e1 commit 7e88c8a

25 files changed

+829
-6
lines changed

Bing.All.sln

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.AspNetCore.Authenticat
220220
EndProject
221221
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TextTemplating", "TextTemplating", "{09A94120-CE45-402F-B45A-21DF04F0C226}"
222222
EndProject
223-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.TextTemplating", "framework\src\Bing.TextTemplating\Bing.TextTemplating.csproj", "{E06DC786-72AB-417B-ACDB-AF00688544EA}"
223+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.TextTemplating", "framework\src\Bing.TextTemplating\Bing.TextTemplating.csproj", "{E06DC786-72AB-417B-ACDB-AF00688544EA}"
224224
EndProject
225-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.TextTemplating.Scriban", "framework\src\Bing.TextTemplating.Scriban\Bing.TextTemplating.Scriban.csproj", "{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83}"
225+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.TextTemplating.Scriban", "framework\src\Bing.TextTemplating.Scriban\Bing.TextTemplating.Scriban.csproj", "{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83}"
226226
EndProject
227-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Test.Shared", "framework\tests\Bing.Test.Shared\Bing.Test.Shared.csproj", "{D6C96AE5-8756-4278-A331-43073E08C3ED}"
227+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Test.Shared", "framework\tests\Bing.Test.Shared\Bing.Test.Shared.csproj", "{D6C96AE5-8756-4278-A331-43073E08C3ED}"
228228
EndProject
229-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Ddd.Domain.Tests", "framework\tests\Bing.Ddd.Domain.Tests\Bing.Ddd.Domain.Tests.csproj", "{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}"
229+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Ddd.Domain.Tests", "framework\tests\Bing.Ddd.Domain.Tests\Bing.Ddd.Domain.Tests.csproj", "{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}"
230+
EndProject
231+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.EventBus", "framework\src\Bing.EventBus\Bing.EventBus.csproj", "{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A}"
232+
EndProject
233+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.EventBus.Tests", "framework\tests\Bing.EventBus.Tests\Bing.EventBus.Tests.csproj", "{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD}"
230234
EndProject
231235
Global
232236
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -510,6 +514,14 @@ Global
510514
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
511515
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
512516
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Release|Any CPU.Build.0 = Release|Any CPU
517+
{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
518+
{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
519+
{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
520+
{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A}.Release|Any CPU.Build.0 = Release|Any CPU
521+
{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
522+
{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
523+
{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
524+
{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD}.Release|Any CPU.Build.0 = Release|Any CPU
513525
EndGlobalSection
514526
GlobalSection(SolutionProperties) = preSolution
515527
HideSolutionNode = FALSE
@@ -610,6 +622,8 @@ Global
610622
{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83} = {09A94120-CE45-402F-B45A-21DF04F0C226}
611623
{D6C96AE5-8756-4278-A331-43073E08C3ED} = {5C7976B4-C243-41B9-8303-8E8FAE099D31}
612624
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94} = {5C7976B4-C243-41B9-8303-8E8FAE099D31}
625+
{5E8AD211-7AEF-4D9D-AFA8-C85B6F3D7C6A} = {B5285F1C-479F-43F5-B3DE-3E930516AF6D}
626+
{0A5D1639-8EEE-4BC9-94A5-04F354FEFBFD} = {5C7976B4-C243-41B9-8303-8E8FAE099D31}
613627
EndGlobalSection
614628
GlobalSection(ExtensibilityGlobals) = postSolution
615629
SolutionGuid = {C1202A0F-83CC-4602-BCE5-20CB640BCAD4}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="project.props" />
3+
4+
<Import Project="project.dependency.props" />
5+
6+
<Import Project="..\..\..\framework.props" />
7+
8+
<ItemGroup>
9+
<Folder Include="Bing\EventBus\Distributed\" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
4+
namespace Bing.EventBus
5+
{
6+
/// <summary>
7+
/// 事件总线(<see cref="IEventBus"/>) 扩展
8+
/// </summary>
9+
public static class EventBusExtensions
10+
{
11+
/// <summary>
12+
/// 发布事件
13+
/// </summary>
14+
/// <param name="eventBus">事件总线</param>
15+
/// <param name="events">事件集合</param>
16+
public static async Task PublishAsync(this IEventBus eventBus, IEnumerable<IEvent> events)
17+
{
18+
foreach (var @event in events)
19+
await eventBus.PublishAsync(@event);
20+
}
21+
22+
/// <summary>
23+
/// 发布事件
24+
/// </summary>
25+
/// <param name="messageEventBus">消息事件总线</param>
26+
/// <param name="events">事件集合</param>
27+
public static async Task PublishAsync(this IMessageEventBus messageEventBus, IEnumerable<IMessageEvent> events)
28+
{
29+
foreach (var @event in events)
30+
await messageEventBus.PublishAsync(@event);
31+
}
32+
}
33+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Bing.EventBus
2+
{
3+
/// <summary>
4+
/// 事件
5+
/// </summary>
6+
public interface IEvent
7+
{
8+
}
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Bing.EventBus
4+
{
5+
/// <summary>
6+
/// 事件总线
7+
/// </summary>
8+
public interface IEventBus
9+
{
10+
/// <summary>
11+
/// 发布事件
12+
/// </summary>
13+
/// <typeparam name="TEvent">事件类型</typeparam>
14+
/// <param name="event">事件</param>
15+
Task PublishAsync<TEvent>(TEvent @event) where TEvent : IEvent;
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Bing.EventBus
2+
{
3+
/// <summary>
4+
/// 事件处理器
5+
/// </summary>
6+
public interface IEventHandler
7+
{
8+
}
9+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
3+
namespace Bing.EventBus
4+
{
5+
/// <summary>
6+
/// 消息事件
7+
/// </summary>
8+
public interface IMessageEvent : IEvent
9+
{
10+
/// <summary>
11+
/// 事件标识
12+
/// </summary>
13+
string Id { get; set; }
14+
15+
/// <summary>
16+
/// 事件发生时间
17+
/// </summary>
18+
DateTime Time { get; set; }
19+
20+
/// <summary>
21+
/// 消息名称
22+
/// </summary>
23+
string Name { get; set; }
24+
25+
/// <summary>
26+
/// 事件数据
27+
/// </summary>
28+
object Data { get; set; }
29+
30+
/// <summary>
31+
/// 回调名称
32+
/// </summary>
33+
string Callback { get; set; }
34+
35+
/// <summary>
36+
/// 是否立即发送消息
37+
/// </summary>
38+
bool Send { get; set; }
39+
}
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Bing.EventBus
4+
{
5+
/// <summary>
6+
/// 消息事件总线
7+
/// </summary>
8+
public interface IMessageEventBus
9+
{
10+
/// <summary>
11+
/// 发布消息
12+
/// </summary>
13+
/// <typeparam name="TEvent">事件类型</typeparam>
14+
/// <param name="event">消息事件</param>
15+
Task PublishAsync<TEvent>(TEvent @event) where TEvent : IMessageEvent;
16+
17+
/// <summary>
18+
/// 发布事件
19+
/// </summary>
20+
/// <param name="name">消息名称</param>
21+
/// <param name="data">事件数据</param>
22+
/// <param name="callback">回调名称</param>
23+
/// <param name="send">是否立即发送过消息</param>
24+
Task PublishAsync(string name, object data, string callback, bool send = false);
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Bing.EventBus.Local
2+
{
3+
/// <summary>
4+
/// 基于内存的本地事件总线
5+
/// </summary>
6+
public interface ILocalEventBus : IEventBus
7+
{
8+
}
9+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Bing.EventBus.Local
4+
{
5+
/// <summary>
6+
/// 本地事件处理器
7+
/// </summary>
8+
public interface ILocalEventHandler : IEventHandler
9+
{
10+
/// <summary>
11+
/// 序号
12+
/// </summary>
13+
int Order { get; }
14+
15+
/// <summary>
16+
/// 是否启用
17+
/// </summary>
18+
bool Enabled { get; }
19+
}
20+
21+
/// <summary>
22+
/// 本地事件处理器
23+
/// </summary>
24+
/// <typeparam name="TEvent">事件类型</typeparam>
25+
public interface ILocalEventHandler<in TEvent> : ILocalEventHandler where TEvent : IEvent
26+
{
27+
/// <summary>
28+
/// 处理事件
29+
/// </summary>
30+
/// <param name="event">事件</param>
31+
Task HandleAsync(TEvent @event);
32+
}
33+
}

0 commit comments

Comments
 (0)