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
Copy file name to clipboardExpand all lines: README.md
+42-3Lines changed: 42 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,9 +35,9 @@ namespace My.Awesome.App
35
35
36
36
### Register instances
37
37
38
-
You can register instances to an unity container using `UnityContainerAttributeRegistration.Attribute.RegisterInstanceProviderAttribute` and `UnityContainerAttributeRegistration.Attribute.RegisterInstanceAttribute`.
38
+
You can register instances to an unity container using `UnityContainerAttributeRegistration.Attribute.RegisterProviderAttribute` and `UnityContainerAttributeRegistration.Attribute.RegisterInstanceAttribute`.
39
39
40
-
Classes marked with `UnityContainerAttributeRegistration.Attribute.RegisterInstanceProviderAttribute` will be instantiated using the container which should be populated with the instances.
40
+
Classes marked with `UnityContainerAttributeRegistration.Attribute.RegisterProviderAttribute` will be instantiated using the container which should be populated with the instances.
41
41
So you can use already registered services to create the instances, which should be later registered.
42
42
43
43
```
@@ -52,7 +52,7 @@ namespace My.Awesome.App
52
52
}
53
53
}
54
54
55
-
[RegisterInstanceProvider]
55
+
[RegisterProvider]
56
56
public class InstanceProvider
57
57
{
58
58
[RegisterInstance]
@@ -61,6 +61,45 @@ namespace My.Awesome.App
61
61
}
62
62
```
63
63
64
+
### Register Factory
65
+
66
+
You can register factory methods to an unity container using `UnityContainerAttributeRegistration.Attribute.RegisterProviderAttribute` and `UnityContainerAttributeRegistration.Attribute.RegisterFactoryAttribute`.
67
+
68
+
Classes marked with `UnityContainerAttributeRegistration.Attribute.RegisterProviderAttribute` will be instantiated using the container which should be populated with the instances.
69
+
So you can use already registered services to create the instances, which should be later registered.
70
+
71
+
Its only important to have the right parameters (see example).
72
+
73
+
```
74
+
namespace My.Awesome.App
75
+
{
76
+
public class Program
77
+
{
78
+
public static void Main(string[] args)
79
+
{
80
+
UnityContainerPopulator populator = new UnityContainerPopulator();
81
+
IUnityContainer container = populator.Populate();
82
+
}
83
+
}
84
+
85
+
[RegisterProvider]
86
+
public class InstanceProvider
87
+
{
88
+
[RegisterFactory]
89
+
public MyClass Factory(IUnityContainer container)
90
+
{
91
+
// do some magic
92
+
}
93
+
94
+
[RegisterFactory]
95
+
public MyClass Factory(IUnityContainer container, Type typeValue, string stringvalue)
96
+
{
97
+
// do some magic
98
+
}
99
+
}
100
+
}
101
+
```
102
+
64
103
### Using a custom container
65
104
66
105
It is possible to populate a already created container.
0 commit comments