StructureMap HowTo: Conditional Construction on Deep Object

后端 未结 1 1767
Happy的楠姐
Happy的楠姐 2021-01-20 08:43

I\'m having difficulty conditionally creating a dependency. Googling, I have yet to find a good example of using the BuildStack and Conditional Predicates.

Here\'s

相关标签:
1条回答
  • 2021-01-20 09:31

    It's often best to try to avoid conditional construction with that syntax, it is much harder to interpret than the For - Use. Your scenario can be solved using:

            For<IDoStuffWithFooA>().Use<DoStuffWithFooA>().Ctor<IFoo>().Is<FooA>();
            For<IDoStuffWithFooB>().Use<DoStuffWithFooB>().Ctor<IFoo>().Is<FooB>();
    
            For<IFoo>().Use<FooZ>();
    
            Scan(
                s =>
                {
                    s.TheCallingAssembly();
                    s.WithDefaultConventions();
                }); 
    
    0 讨论(0)
提交回复
热议问题