-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlueBox.cs
83 lines (69 loc) · 2.36 KB
/
GlueBox.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Reflection;
using HanneBogaerts.GlueBox.DI;
using HanneBogaerts.GlueBox.Logging;
using Serilog;
namespace HanneBogaerts.GlueBox;
public class GlueBox
{
private readonly AdhesionRegistry _adhesionRegistry = new();
private readonly AdhesionManager _adhesionManager = new();
private readonly AdhesionResolver _adhesionResolver;
public GlueBox()
{
LoggingManager.InitializeLogger();
_adhesionResolver = new AdhesionResolver(_adhesionRegistry, _adhesionManager);
}
public void StickSingleton<TImplementation>()
{
_adhesionRegistry.StickSingleton<TImplementation>();
_adhesionManager.AddDependencies<TImplementation>();
}
public void StickSingleton<TService, TImplementation>()
{
_adhesionRegistry.StickSingleton<TService, TImplementation>();
_adhesionManager.AddDependencies<TImplementation>();
}
public void StickTransient<TImplementation>()
{
_adhesionRegistry.StickTransient<TImplementation>();
_adhesionManager.AddDependencies<TImplementation>();
}
public void StickTransient<TService, TImplementation>()
{
_adhesionRegistry.StickTransient<TService, TImplementation>();
_adhesionManager.AddDependencies<TImplementation>();
}
public TService Resolve<TService>()
{
return _adhesionResolver.Resolve<TService>();
}
public void CompleteAdhesion()
{
Log.Debug("Completing adhesion");
var assembly = Assembly.GetCallingAssembly();
var controllerTypes = assembly.GetTypes()
.Where(type => typeof(IGlueController).IsAssignableFrom(type) && !type.IsAbstract);
foreach (var type in controllerTypes)
{
Log.Debug("Sticking singleton of type {Type}", type.Name);
_adhesionRegistry.StickSingleton(type);
_adhesionManager.AddDependencies(type);
}
}
public Dictionary<string, Action> GetCommandAdhesionMap()
{
return _adhesionResolver.CommandAdhesionMap;
}
public static void SetLogLevel(string level)
{
LoggingManager.SetLogLevel(level);
}
public static void ChangeLogOutput(string method)
{
LoggingManager.ChangeLogOutput(method);
}
public static void ChangeLogOutput(string method, string path)
{
LoggingManager.ChangeLogOutput(method, path);
}
}