-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEventGridOptions.cs
More file actions
43 lines (38 loc) · 1.48 KB
/
EventGridOptions.cs
File metadata and controls
43 lines (38 loc) · 1.48 KB
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 System;
using SharpEventGrid;
namespace SharpEventGridServer
{
public class EventGridOptions
{
protected Type _defaultMapping;
internal IServiceProvider ServiceProvider { get; set; }
public string EventsPath { get; set; } = "api/events";
public bool AutoValidateSubscription { get; set; } = true;
public Action ValidateSubscriptionCallBack { get; set; }
public string ValidationKey { get; set; }
public string ValidationValue { get; set; }
public Action<string, bool, string> AutoValidateSubscriptionAttemptNotifier { get; set; }
public EventGridMapper Mapper = new EventGridMapper();
public virtual void MapEvent<T>(string eventType) where T : IEventGridHandler
{
Mapper.AddMapping(eventType, typeof(T));
}
public void MapDefault<T>() where T : IEventGridHandler
{
_defaultMapping = typeof(T);
}
public void SetValidationKey(string key, string value)
{
ValidationKey = key;
ValidationValue = value;
}
internal virtual IEventGridHandler ResolveHandler(Event item)
{
var typeToCreate = Mapper.LookUpMapping(item);
if (typeToCreate == null)
typeToCreate = _defaultMapping;
var handler = ServiceProvider.GetService(typeToCreate) ?? Activator.CreateInstance(typeToCreate);
return (IEventGridHandler)handler;
}
}
}