With StructureMap is it possible to make a Singlet

2019-05-16 20:02发布

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("alpha").EqualToAppSetting("Alpha")
    .WithCtorArg("beta").EqualToAppSetting("Beta");

Suggestions?

1条回答
仙女界的扛把子
2楼-- · 2019-05-16 20:24

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");
查看更多
登录 后发表回答