-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
DryIocContainerExtension.cs
85 lines (70 loc) · 2.35 KB
/
DryIocContainerExtension.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 DryIoc;
using Prism.Ioc;
namespace Prism.DryIoc.Ioc
{
public class DryIocContainerExtension : IContainerExtension<IContainer>
{
public IContainer Instance { get; }
public DryIocContainerExtension(IContainer container)
{
Instance = container;
}
public void FinalizeExtension() { }
public IContainerRegistry RegisterInstance(Type type, object instance)
{
Instance.UseInstance(type, instance);
return this;
}
public IContainerRegistry RegisterInstance(Type type, object instance, string name)
{
Instance.UseInstance(type, instance, serviceKey: name);
return this;
}
public IContainerRegistry RegisterSingleton(Type from, Type to)
{
Instance.Register(from, to, Reuse.Singleton);
return this;
}
public IContainerRegistry RegisterSingleton(Type from, Type to, string name)
{
Instance.Register(from, to, Reuse.Singleton, serviceKey: name);
return this;
}
public IContainerRegistry Register(Type from, Type to)
{
Instance.Register(from, to);
return this;
}
public IContainerRegistry Register(Type from, Type to, string name)
{
Instance.Register(from, to, serviceKey: name);
return this;
}
public object Resolve(Type type)
{
return Instance.Resolve(type);
}
public object Resolve(Type type, string name)
{
return Instance.Resolve(type, serviceKey: name);
}
public object Resolve(Type type, params (Type Type, object Instance)[] parameters)
{
return Instance.Resolve(type, args: parameters.Select(p => p.Instance).ToArray());
}
public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters)
{
return Instance.Resolve(type, name, args: parameters.Select(p => p.Instance).ToArray());
}
public bool IsRegistered(Type type)
{
return Instance.IsRegistered(type);
}
public bool IsRegistered(Type type, string name)
{
return Instance.IsRegistered(type, name);
}
}
}