1
public abstract class BattleVehicle : IVehicle {
  public BattleVehicle (IList<IGuns> someGuns, ISolider driver) { /*...*/ }
}
public class BigAssTank : BattleVehicle, ITank { /*...*/ }
public class AngryBirdsAPC : BattleVehicle, IAPC { /*...*/ }
//and a lot more of these battle vehicles .... 

现在,按照标准,我希望每辆战车注册 2 把手枪List<Pistols> twoPistols和 1把Rookie : ISolider作为默认驾驶员。我该怎么做呢?

我期待类似的东西:

container.Register(Classes
                  .FromAssemblyContaining<IVehicle>()
                  .BasedOn<IVehicle>()
                  .DependsOn(new {someGuns = twoPistols, driver = rookie}) //won't work here....

这当然行不通。从 09 年开始,我只在这里找到了一篇相当老的帖子。我不确定现在流利地注册所有具体车辆的正确方法是什么。请帮助和/或将我链接到任何高级自动注册教程?

4

1 回答 1

1

您应该使用Configure扩展方法。用法:

container.Register(
    Classes
        .FromAssemblyContaining<IVehicle>()
        .BasedOn<IVehicle>()
        .Configure(k => 
            k.DependsOn(new {someGuns = twoPistols, driver = rookie})))
于 2012-08-06T06:22:32.803 回答