File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ public class MyDependencyFactory
184
184
185
185
## Caching singletons in generic types
186
186
187
- If you need to cache an instance of something based on type , then you can store it on the field of a generic type .
187
+ 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 .
188
188
189
189
```C #
190
190
public class Factory
@@ -194,9 +194,9 @@ public class Factory
194
194
return Cache <T >.Instance ;
195
195
}
196
196
197
- private class Cache < T >
197
+ private static class Cache < T >
198
198
{
199
- public T Instance = new T ();
199
+ public static T Instance = new T ();
200
200
}
201
201
}
202
202
```
@@ -211,11 +211,11 @@ public class Factory
211
211
return Cache <T >.Instance ;
212
212
}
213
213
214
- private class Cache < T >
214
+ private static class Cache < T >
215
215
{
216
- public T Instance = CallExpensiveMethodToBuildANewInstance ();
216
+ public static T Instance = CallExpensiveMethodToBuildANewInstance ();
217
217
218
- public T CallExpensiveMethodToBuildANewInstance ()
218
+ public static T CallExpensiveMethodToBuildANewInstance ()
219
219
{
220
220
// Imagine a really complex process to construct T
221
221
return instance .
You can’t perform that action at this time.
0 commit comments