开发者

With StructureMap is it possible to make a Singleton object AND provide constructor arguments?

开发者 https://www.devze.com 2022-12-08 21:36 出处:网络
I can\'t seem to figure out how to define a object as a singleton AND define two arguments for the constructor.

I can't seem to figure out how to define a object as a singleton AND define two arguments for the constructor.

I can do either / or .. just not at the same time.

Eg. (this doesn't work)...

ForRequestedType<IFoo>()
    .TheDefaultIsConcreteType<Foo>()
    .CacheBy(InstanceScope.Singleton)
    .WithCtorArg("al开发者_如何学Cpha").EqualToAppSetting("Alpha")
    .WithCtorArg("beta").EqualToAppSetting("Beta");

Suggestions?


You are very close. The trick is that you need to use the alternate default DSL language TheDefault.Is.OfConcreteType

ForRequestedType<IFoo>()
    .CacheBy(InstanceScope.Singleton)
    .TheDefault.Is.OfConcreteType<Foo>()
    .WithCtorArg("alpha").EqualToAppSetting("alpha")
    .WithCtorArg("beta").EqualToAppSetting("beta");
0

精彩评论

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