[英]Help with basic structuremap wiring
var container = new Container(x =>
{
x.For<IEngine>().Use<V6Engine>();
x.For<ICar>().Use<HondaCar>();
}
);
ICar car = ObjectFactory.GetInstance<ICar>();
Console.WriteLine(car.Noise());
I am getting the error: 我收到错误消息:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily ClassLibrary1.ICar, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
I read the quickstart, and I understood that if you wireup a particular interface that is also used in a constructor, you don't have to explicitly wireup the interface in each classes constructure. 我阅读了快速入门,并且了解到,如果您对也用于构造函数中的特定接口进行接线,则不必在每个类构造中显式地对接口进行接线。
So in the above, I wired up IEngine to V6Engine, and then ICar to HondaCar (that has a constructor that has an IEngine that I have already wired up). 因此,在上面,我将IEngine连接到V6Engine,然后将ICar连接到HondaCar(该汽车的构造函数具有已连接的IEngine)。
Why does this not work? 为什么这不起作用?
try : 尝试:
container.GetInstance<ICar>();
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.