-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubscription.cs
53 lines (45 loc) · 1.44 KB
/
Subscription.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
44
45
46
47
48
49
50
51
52
53
using Salday.EventBus.Interfaces;
using System;
using System.Collections.Generic;
namespace Salday.EventBus
{
internal class Subscription : ISubscription
{
/// <summary>
/// Object used for handler lookup
/// </summary>
public object EventProxy { get; }
/// <summary>
/// Event bus, that this subscribtion belong to
/// </summary>
public IEventBus EventBus { get; }
/// <summary>
/// Defines, if handlers are active (It is not restrictive, should check that inside handler manually)
/// </summary>
public bool Active { get; set; } = true;
/// <summary>
/// All registred handlers
/// </summary>
public IDictionary<Type, IList<IHandler>> Handlers { get; }
public Subscription(object eventProxy, IEventBus evBus, IDictionary<Type, IList<IHandler>> handlers)
{
this.EventProxy = eventProxy;
this.EventBus = evBus;
this.Handlers = handlers;
foreach (var handlerCollection in handlers.Values)
{
foreach (var handler in handlerCollection)
{
handler.Subscription = this;
}
}
}
/// <summary>
/// Removes subsription from event bus
/// </summary>
public void Dispose()
{
EventBus.RemoveSubscription(this);
}
}
}