开发者

Structuremap - Caching a single object instance for all request

开发者 https://www.devze.com 2023-01-08 13:09 出处:网络
if I want StructureMap to return a single object instance for all requests, is there any difference at all between the two methods

if I want StructureMap to return a single object instance for all requests, is there any difference at all between the two methods below??

StructureMap.ObjectFactory.Initialize(x 开发者_StackOverflow=> {x
   .ForRequestedType<ISplitPaymentConfigurationReader>()
   .TheDefaultIsConcreteType<SplitPaymentConfigurationReader>()
   .CacheBy(StructureMap.Attributes.InstanceScope.Singleton);
});

and

StructureMap.ObjectFactory.Inject<ISplitPaymentConfigurationReader>(
 new SplitPaymentConfigurationReader());


As answered by the great folks in StructureMap, the two are the same, except that with the first way, you get auto-wiring of dependencies, where you don't with the second way.

0

精彩评论

暂无评论...
验证码 换一张
取 消