帮助进行基本结构图接线
var container = new Container(x =>
{
x.For<IEngine>().Use<V6Engine>();
x.For<ICar>().Use<HondaCar>();
}
);
ICar car = ObjectFactory.GetInstance<ICar>();
Console.WriteLine(car.Noise());
我收到错误:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily ClassLibrary1.ICar, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
我阅读了快速入门,并且我了解到,如果您连接也在构造函数中使用的特定接口,则不必在每个类构造中显式连接该接口。
因此,在上面,我将 IEngine 连接到 V6Engine,然后将 ICar 连接到 HondaCar(它有一个构造函数,该构造函数具有我已经连接的 IEngine)。
为什么这不起作用?
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).
Why does this not work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
希望有帮助。
try :
Hope it helps.