You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+66-5Lines changed: 66 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,22 @@
1
-
# Lite Event Aggregator and IPC Tranporter
1
+
# Lite Event Aggregator and IPC Transporter
2
2
3
-
Lite.EventIPC is a cross-platform local Event Aggregator and remote IPC service library for C#. The pattern is used for decoupling publishers and subscribers in a single or multiple applications. The library can be easily extended for custom IPC transports using the `IEventTransport` interface to suit your needs (_need I say, DBus?_)
3
+
Lite.EventIPC is a cross-platform local Event Aggregator and remote IPC (inter-process communication) service library for C#. The pattern is used for decoupling publishers and subscribers in a single or multiple applications. The library can be easily extended for custom IPC transports using the `IEventTransport` interface to suit your needs (_need I say, DBus?_)
4
4
5
5
The Event Aggregator service in C# pattern is useful for decoupling publishers and subscribers in an application.
6
6
7
7
## Features
8
8
9
9
This implementation is features:
10
10
11
-
* Simple and thread-safe
11
+
* Simple, thread-safe, and async friendly
12
+
* Local subscribe/publish event aggregator
13
+
*`Subscribe` and `Publish` - for one-way events
14
+
*`SubscribeRequest` and `RequestAsync` - for publishing with an awaited response (_including timeouts_)
12
15
* Uses **weak references** to avoid memory leaks
13
16
* Cleans up dead references during `Publish`.
14
17
* Prevents memory leaks when subscribers are no longer needed.
15
18
* DI-friendly with extensions and hosted service
16
-
*Optional IPC transport mechanisms for inter-process communication (IPC) with **JSON serialization**:
19
+
*Built-in IPC transport mechanisms (_inter-process communication_) with **JSON serialization**:
17
20
* Named Pipe Transport
18
21
* Memory-Mapped File Transport (_Windows OS only_)
19
22
* TCP/IP Transport
@@ -23,14 +26,16 @@ This implementation is features:
23
26
24
27
## Usage
25
28
29
+
### Basic Subscribe/Publish
30
+
26
31
```cs
32
+
usingLite.EventIpc;
27
33
28
34
publicclassUserCreatedEvent
29
35
{
30
36
publicstringUserName { get; set; }
31
37
}
32
38
33
-
34
39
staticvoidMain()
35
40
{
36
41
vareventAggregator=newEventAggregator();
@@ -44,6 +49,62 @@ static void Main()
44
49
}
45
50
```
46
51
52
+
### Publish Requests with Awaited Responses
53
+
54
+
Subscribing to a **request** event allows users to respond with a different object. This is useful for RPC-like communication.
55
+
56
+
```cs
57
+
usingLite.EventIpc;
58
+
59
+
publicasyncTaskSubscribeWithResponse()
60
+
{
61
+
// Subscribe to Ping events that respond with Pong
Borrowing from the previous example, you can specify a timeout when sending a request event. If no subscriber responds within the timeout period, `null` is returned.
84
+
85
+
```cs
86
+
publicasyncTaskSubscribeWithResponse()
87
+
{
88
+
// ...
89
+
90
+
// Send a Ping request event and await the Pong response
Copy file name to clipboardExpand all lines: src/Lite.EventIpc.Tests/BaseTestClass.cs
+17-7Lines changed: 17 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,42 @@
2
2
// See the LICENSE file in the project root for more information.
3
3
4
4
usingMicrosoft.Extensions.Logging;
5
+
usingMicrosoft.Extensions.Logging.Console;
5
6
6
7
namespaceLite.EventIpc.Tests;
7
8
8
9
[TestClass]
10
+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design","MSTEST0016:Test class should have test method",Justification="Its a base class")]
9
11
publicclassBaseTestClass
10
12
{
11
-
/// <summary>Default timeout.. don't wait too long.</summary>
12
-
publicconstintDefaultTimeout=50;
13
+
/// <summary>Timeout 200 milliseconds.</summary>
14
+
publicconstintTimeout200=200;
13
15
14
-
publicconstintDefaultTimeout200=200;
16
+
/// <summary>Timeout 50 milliseconds.</summary>
17
+
publicconstintTimeout50=50;
15
18
16
19
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules","SA1401:Fields should be private",Justification="This is a parent class")]
0 commit comments