Skip to content

Commit 62ebb50

Browse files
author
maximv
committed
fixed: #238
1 parent 48281fc commit 62ebb50

File tree

2 files changed

+53
-72
lines changed

2 files changed

+53
-72
lines changed

docs/DryIoc.Docs/KindsOfChildContainer.cs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- [No child containers](#no-child-containers)
99
- [Facade](#facade)
1010
- [With different Rules and ScopeContext](#with-different-rules-and-scopecontext)
11-
- [With expression generation](#with-expression-generation)
1211
- [Without Cache](#without-cache)
1312
- [Without Singletons](#without-singletons)
1413
- [With registrations copy](#with-registrations-copy)
@@ -89,11 +88,17 @@ public void Facade_for_tests()
8988
Actually, `CreateFacade` does not do anything magic. It uses a `With` method to create a new container with
9089
a new default `serviceKey` and set a rule to prefer this `serviceKey` over default:
9190
92-
```cs
93-
public static IContainer CreateFacade(this IContainer container, string facadeKey = FacadeKey) =>
94-
container.With(rules => rules
95-
.WithDefaultRegistrationServiceKey(facadeKey)
96-
.WithFactorySelector(Rules.SelectKeyedOverDefaultFactory(facadeKey)));
91+
```cs md*/
92+
static class CreateFacade_implementation
93+
{
94+
public const string FacadeKey = "@facade";
95+
96+
public static IContainer CreateFacade_example(this IContainer container, string facadeKey = FacadeKey) =>
97+
container.With(rules => rules
98+
.WithDefaultRegistrationServiceKey(facadeKey)
99+
.WithFactorySelector(Rules.SelectKeyedOverDefaultFactory(facadeKey)));
100+
}
101+
/*md
97102
```
98103
99104
__Note:__ In case the `CreateFacade` does no meet your use-case, you may always go one level deeper in API and
@@ -102,7 +107,7 @@ public static IContainer CreateFacade(this IContainer container, string facadeKe
102107
103108
## With different Rules and ScopeContext
104109
105-
As it said above, you may provide a new `rules` and `scopeContext` using the `With` method.
110+
As it said above you may provide the new `rules` and `scopeContext` using the `With` method.
106111
107112
Setting rules is a very common thing, so there is a dedicated `With` overload for this:
108113
```cs
@@ -111,36 +116,22 @@ IContainer With(this IContainer container,
111116
IScopeContext scopeContext = null)
112117
```
113118
114-
The important and may be not clear point, what happens with a parent registry in a new container.
115-
The answer is the __registry is cloned__ and the __cache is dropped__. The cache is dropped, because
116-
the new rules may lead to resolving a new services in a child container, different from the already
119+
The important and maybe not as much clear point is what happens with the parent registry in the new container.
120+
The answer is that __the registry is copied__ and the __cache is dropped__. The cache is dropped because
121+
the new rules may lead to the resolving the new services in the child container different from the already
117122
resolved services in the parent. Therefore, we need to drop (invalidate) the cache to stop serving the
118123
wrong results.
119124
120-
The cloned registry means that new registration made into child container won't appear in the parent,
121-
and vice versa. The reason is not only an isolation of parent from the changes in child, but also there are
125+
The copied (cloned) registry means that the new registration made into the child container won't appear in the parent,
126+
and vice versa. The reason is not only the isolation of the parent from the changes in the child but also there are
122127
rules that affect how registrations are done, e.g. `DefaultRegistrationServiceKey`.
123128
124-
## With expression generation
125-
126-
```cs
127-
public static IContainer WithExpressionGeneration(this IContainer container)
128-
```
129-
130-
Will store the expressions built for service resolution.
131-
This is used in `Validate` and `GenerateResolutionExpressions` methods described
132-
[here](ErrorDetectionAndResolution-#Service-Registrations-Diagnostics).
133-
134-
135129
## Without Cache
136130
137-
Cache in DryIoc usually means a some artifacts stored while resolving services.
138-
139-
More precisely, the resolution cache contains a set of `FactoryDelegate` compiled from expression trees
140-
to create an actual services.
131+
Cache in DryIoc usually means the expressions and delegates created and stored in the container while resolving the services.
141132
142-
The reason for removing cache may be changing or removing a service registration after the fact,
143-
when the resolutions were already made from Container and were cached internally.
133+
The reason for removing the cache may be the changing or removing the service registration after the fact -
134+
when the resolutions were already made and the things were cached.
144135
145136
```cs md*/
146137
class Without_cache
@@ -201,13 +192,13 @@ public void Example()
201192
}/*md
202193
```
203194
204-
The method will clone the container registrations but will drop cache.
195+
The method will clone the container registrations but will drop the cache.
205196
206197
207198
## With registrations copy
208199
209-
`WithRegistrationsCopy` will create a container clone (child) where new registration will be isolated from the parent
210-
and vice versa.
200+
`WithRegistrationsCopy` will create a container clone (child) where the new registration will be isolated from the parent
201+
and the vice versa.
211202
212203
md*/
213204

@@ -237,11 +228,11 @@ public void Example()
237228
}/*md
238229
```
239230
240-
Again, a cloning here is the fast `O(1)` operation.
231+
Again, the cloning here is the fast `O(1)` operation.
241232
242-
By default, the cache is dropped, but you may pass optional argument `preserveCache: true` to keep the cache.
243-
For instance in the example above, we atr just adding a new registration without replacing anything,
244-
so the cache from the parent will work just fine.
233+
By default, the cache is dropped but you may pass the optional argument `preserveCache: true` to keep the cache.
234+
For instance in the example above we are just adding a new registration without replacing anything,
235+
so the cache from the parent will proceed to be valid and useful.
245236
246237
247238
## With no more registration allowed

docs/DryIoc.Docs/KindsOfChildContainer.md

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- [No child containers](#no-child-containers)
88
- [Facade](#facade)
99
- [With different Rules and ScopeContext](#with-different-rules-and-scopecontext)
10-
- [With expression generation](#with-expression-generation)
1110
- [Without Cache](#without-cache)
1211
- [Without Singletons](#without-singletons)
1312
- [With registrations copy](#with-registrations-copy)
@@ -88,11 +87,16 @@ class FacadeExample
8887
Actually, `CreateFacade` does not do anything magic. It uses a `With` method to create a new container with
8988
a new default `serviceKey` and set a rule to prefer this `serviceKey` over default:
9089

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+
}
96100
```
97101

98102
__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.
101105

102106
## With different Rules and ScopeContext
103107

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.
105109

106110
Setting rules is a very common thing, so there is a dedicated `With` overload for this:
107111
```cs
@@ -110,36 +114,22 @@ IContainer With(this IContainer container,
110114
IScopeContext scopeContext = null)
111115
```
112116

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
116120
resolved services in the parent. Therefore, we need to drop (invalidate) the cache to stop serving the
117121
wrong results.
118122

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
121125
rules that affect how registrations are done, e.g. `DefaultRegistrationServiceKey`.
122126

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-
134127
## Without Cache
135128

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.
140130

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.
143133

144134
```cs
145135
class Without_cache
@@ -200,13 +190,13 @@ class Without_singletons
200190
}
201191
```
202192

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.
204194

205195

206196
## With registrations copy
207197

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.
210200

211201

212202
class With_registrations_copy
@@ -235,11 +225,11 @@ class With_registrations_copy
235225
}
236226
```
237227
238-
Again, a cloning here is the fast `O(1)` operation.
228+
Again, the cloning here is the fast `O(1)` operation.
239229
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.
243233
244234
245235
## With no more registration allowed

0 commit comments

Comments
 (0)