You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can register instances to an unity container using `UnityContainerAttributeRegistration.Attribute.RegisterInstanceProviderAttribute` and `UnityContainerAttributeRegistration.Attribute.RegisterInstanceAttribute`.
39
+
40
+
Classes marked with `UnityContainerAttributeRegistration.Attribute.RegisterInstanceProviderAttribute` will be instantiated using the container which should be populated with the instances.
41
+
So you can use already registered services to create the instances, which should be later registered.
42
+
43
+
```
44
+
namespace My.Awesome.App
45
+
{
46
+
public class Program
47
+
{
48
+
public static void Main(string[] args)
49
+
{
50
+
UnityContainerPopulator populator = new UnityContainerPopulator();
51
+
IUnityContainer container = populator.Populate();
52
+
}
53
+
}
54
+
55
+
[RegisterInstanceProvider]
56
+
public class InstanceProvider
57
+
{
58
+
[RegisterInstance]
59
+
public string Token = "Hard coded token";
60
+
}
61
+
}
62
+
```
63
+
64
+
### Using a custom container
65
+
66
+
It is possible to populate a already created container.
67
+
68
+
```
69
+
namespace My.Awesome.App
70
+
{
71
+
public class Program
72
+
{
73
+
public static void Main(string[] args)
74
+
{
75
+
IUnityContainer container = new UnityContainer();
76
+
UnityContainerPopulator populator = new UnityContainerPopulator();
77
+
populator.Populate(container);
78
+
}
79
+
}
80
+
}
81
+
```
82
+
83
+
### Restrict the checked assemblies
84
+
85
+
You can restrict the assemblies to check, e. g. to create a container only containing registrations of one assembly.
86
+
87
+
```
88
+
namespace My.Awesome.App
89
+
{
90
+
public class Program
91
+
{
92
+
public static void Main(string[] args)
93
+
{
94
+
IAssemblyProvider assemblyProvider = new CustomAssemblyProvider();
95
+
UnityContainerPopulator populator = new UnityContainerPopulator(assemblyProvider);
96
+
IUnityContainer container = populator.Populate();
97
+
}
98
+
}
99
+
100
+
public class CustomAssemblyProvider : IAssemblyProvider
0 commit comments