Skip to content

Commit 9ac6707

Browse files
authored
Merge pull request #3 from poke/singletons-static
2 parents 783f4d2 + a752c45 commit 9ac6707

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

1.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public class MyDependencyFactory
186186

187187
## Caching singletons in generic types
188188

189-
If you need to cache an instance of something based on type, then you can store it on the field of a generic type.
189+
If you need to cache an instance of something based on type, then you can store it on a static field of a generic type.
190190

191191
```C#
192192
public class Factory
@@ -196,9 +196,9 @@ public class Factory
196196
return Cache<T>.Instance;
197197
}
198198

199-
private class Cache<T>
199+
private static class Cache<T>
200200
{
201-
public T Instance = new T();
201+
public static T Instance = new T();
202202
}
203203
}
204204
```
@@ -213,11 +213,11 @@ public class Factory
213213
return Cache<T>.Instance;
214214
}
215215

216-
private class Cache<T>
216+
private static class Cache<T>
217217
{
218-
public T Instance = CallExpensiveMethodToBuildANewInstance();
218+
public static T Instance = CallExpensiveMethodToBuildANewInstance();
219219

220-
public T CallExpensiveMethodToBuildANewInstance()
220+
public static T CallExpensiveMethodToBuildANewInstance()
221221
{
222222
// Imagine a really complex process to construct T
223223
return instance.

0 commit comments

Comments
 (0)