-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHandlerT.cs
43 lines (35 loc) · 1.11 KB
/
HandlerT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Salday.EventBus.Interfaces;
using System;
namespace Salday.EventBus
{
internal sealed class Handler<TEvent> : IHandler<TEvent> where TEvent : EventBase
{
/// <summary>
/// Action that is called when event is received
/// </summary>
public Action<TEvent> Action { get; }
/// <summary>
/// Type of messages, accepted by this handler
/// </summary>
public Type HandledType { get; }
/// <summary>
/// Priority of this handler
/// </summary>
public HandlerPriority Priority { get; }
/// <summary>
/// Subscription, that this handler is bound to
/// </summary>
public ISubscription Subscription { get; set; }
public Handler(Type handledType, HandlerPriority priority, Action<TEvent> action)
{
this.HandledType = handledType;
this.Priority = priority;
this.Action = action;
}
public void Handle(TEvent eventObj)
{
if (Subscription.Active)
Action?.Invoke(eventObj);
}
}
}