简体   繁体   中英

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).

Why does this not work?

try :

container.GetInstance<ICar>();

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM