-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
UnityContainerExtension.cs
85 lines (70 loc) · 2.44 KB
/
UnityContainerExtension.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
84
85
using System;
using System.Linq;
using Prism.Ioc;
using Unity;
using Unity.Resolution;
namespace Prism.Unity
{
public sealed class UnityContainerExtension : IContainerExtension<IUnityContainer>
{
public IUnityContainer Instance { get; }
public UnityContainerExtension(IUnityContainer container) => Instance = container;
public void FinalizeExtension() { }
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.RegisterInstance(type, instance);
return this;
}
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.RegisterInstance(type, name, instance);
return this;
}
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.RegisterSingleton(from, to);
return this;
}
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.RegisterSingleton(from, to, name);
return this;
}
public IContainerRegistry Register(Type from, Type to)
{
Instance.RegisterType(from, to);
return this;
}
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.RegisterType(from, to, name);
return this;
}
public object Resolve(Type type)
{
return Instance.Resolve(type);
}
public object Resolve(Type type, string name)
{
return Instance.Resolve(type, name);
}
public object Resolve(Type type, params (Type Type, object Instance)[] parameters)
{
var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray();
return Instance.Resolve(type, overrides);
}
public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters)
{
var overrides = parameters.Select(p => new DependencyOverride(p.Type, p.Instance)).ToArray();
return Instance.Resolve(type, name, overrides);
}
public bool IsRegistered(Type type)
{
return Instance.IsRegistered(type);
}
public bool IsRegistered(Type type, string name)
{
return Instance.IsRegistered(type, name);
}
}
}