Castle Windsor: How to specify a constructor parameter from code?

前端 未结 6 490
轻奢々
轻奢々 2020-12-30 08:34

Say I have the following class

MyComponent : IMyComponent {
  public MyComponent(int start_at) {...}
}

I can register an instance of it wit

6条回答
  •  庸人自扰
    2020-12-30 09:30

    Try this

    int start_at = 1; 
    container.Register(Component.For().DependsOn(dependency: Dependency.OnValue(start_at)));
    

提交回复
热议问题