7
7
- [ No child containers] ( #no-child-containers )
8
8
- [ Facade] ( #facade )
9
9
- [ With different Rules and ScopeContext] ( #with-different-rules-and-scopecontext )
10
- - [ With expression generation] ( #with-expression-generation )
11
10
- [ Without Cache] ( #without-cache )
12
11
- [ Without Singletons] ( #without-singletons )
13
12
- [ With registrations copy] ( #with-registrations-copy )
@@ -88,11 +87,16 @@ class FacadeExample
88
87
Actually, ` CreateFacade ` does not do anything magic. It uses a ` With ` method to create a new container with
89
88
a new default ` serviceKey ` and set a rule to prefer this ` serviceKey ` over default:
90
89
91
- ``` cs
92
- public static IContainer CreateFacade (this IContainer container , string facadeKey = FacadeKey ) =>
93
- container .With (rules => rules
94
- .WithDefaultRegistrationServiceKey (facadeKey )
95
- .WithFactorySelector (Rules .SelectKeyedOverDefaultFactory (facadeKey )));
90
+ ``` cs
91
+ static class CreateFacade_implementation
92
+ {
93
+ public const string FacadeKey = " @facade" ;
94
+
95
+ public static IContainer CreateFacade_example (this IContainer container , string facadeKey = FacadeKey ) =>
96
+ container .With (rules => rules
97
+ .WithDefaultRegistrationServiceKey (facadeKey )
98
+ .WithFactorySelector (Rules .SelectKeyedOverDefaultFactory (facadeKey )));
99
+ }
96
100
```
97
101
98
102
__ Note:__ In case the ` CreateFacade ` does no meet your use-case, you may always go one level deeper in API and
@@ -101,7 +105,7 @@ select your set of rules and arguments for the `With` method.
101
105
102
106
## With different Rules and ScopeContext
103
107
104
- As it said above, you may provide a new ` rules ` and ` scopeContext ` using the ` With ` method.
108
+ As it said above you may provide the new ` rules ` and ` scopeContext ` using the ` With ` method.
105
109
106
110
Setting rules is a very common thing, so there is a dedicated ` With ` overload for this:
107
111
``` cs
@@ -110,36 +114,22 @@ IContainer With(this IContainer container,
110
114
IScopeContext scopeContext = null )
111
115
```
112
116
113
- The important and may be not clear point, what happens with a parent registry in a new container.
114
- The answer is the __ registry is cloned __ and the __ cache is dropped__ . The cache is dropped, because
115
- the new rules may lead to resolving a new services in a child container, different from the already
117
+ The important and maybe not as much clear point is what happens with the parent registry in the new container.
118
+ The answer is that __ the registry is copied __ and the __ cache is dropped__ . The cache is dropped because
119
+ the new rules may lead to the resolving the new services in the child container different from the already
116
120
resolved services in the parent. Therefore, we need to drop (invalidate) the cache to stop serving the
117
121
wrong results.
118
122
119
- The cloned registry means that new registration made into child container won't appear in the parent,
120
- and vice versa. The reason is not only an isolation of parent from the changes in child, but also there are
123
+ The copied ( cloned) registry means that the new registration made into the child container won't appear in the parent,
124
+ and vice versa. The reason is not only the isolation of the parent from the changes in the child but also there are
121
125
rules that affect how registrations are done, e.g. ` DefaultRegistrationServiceKey ` .
122
126
123
- ## With expression generation
124
-
125
- ``` cs
126
- public static IContainer WithExpressionGeneration (this IContainer container )
127
- ```
128
-
129
- Will store the expressions built for service resolution.
130
- This is used in ` Validate ` and ` GenerateResolutionExpressions ` methods described
131
- [ here] ( ErrorDetectionAndResolution-#Service-Registrations-Diagnostics ) .
132
-
133
-
134
127
## Without Cache
135
128
136
- Cache in DryIoc usually means a some artifacts stored while resolving services.
137
-
138
- More precisely, the resolution cache contains a set of ` FactoryDelegate ` compiled from expression trees
139
- to create an actual services.
129
+ Cache in DryIoc usually means the expressions and delegates created and stored in the container while resolving the services.
140
130
141
- The reason for removing cache may be changing or removing a service registration after the fact,
142
- when the resolutions were already made from Container and were cached internally .
131
+ The reason for removing the cache may be the changing or removing the service registration after the fact -
132
+ when the resolutions were already made and the things were cached.
143
133
144
134
``` cs
145
135
class Without_cache
@@ -200,13 +190,13 @@ class Without_singletons
200
190
}
201
191
```
202
192
203
- The method will clone the container registrations but will drop cache.
193
+ The method will clone the container registrations but will drop the cache.
204
194
205
195
206
196
## With registrations copy
207
197
208
- ` WithRegistrationsCopy ` will create a container clone (child) where new registration will be isolated from the parent
209
- and vice versa.
198
+ ` WithRegistrationsCopy ` will create a container clone (child) where the new registration will be isolated from the parent
199
+ and the vice versa.
210
200
211
201
212
202
class With_registrations_copy
@@ -235,11 +225,11 @@ class With_registrations_copy
235
225
}
236
226
```
237
227
238
- Again, a cloning here is the fast `O(1)` operation.
228
+ Again, the cloning here is the fast `O(1)` operation.
239
229
240
- By default, the cache is dropped, but you may pass optional argument `preserveCache: true` to keep the cache.
241
- For instance in the example above, we atr just adding a new registration without replacing anything,
242
- so the cache from the parent will work just fine .
230
+ By default, the cache is dropped but you may pass the optional argument `preserveCache: true` to keep the cache.
231
+ For instance in the example above we are just adding a new registration without replacing anything,
232
+ so the cache from the parent will proceed to be valid and useful .
243
233
244
234
245
235
## With no more registration allowed
0 commit comments