Windsor依赖注入属性

时间:2014-06-30 11:51:25

标签: c# dependency-injection castle-windsor

我有一个温莎容器,温莎不会注入我的财产。奇怪的是,ServiceA依赖关系已解决,但与组件无关。

Container.AddFacility<WcfFacility>();
Container.Register(Component.For<PublisherService>().AsWcfService());
Container.Register(Component.For<IExecutionProgram>().ImplementedBy<ExecutionProgram>());
Container.Register(Component.For<IValidationProgram>().Instance(Factory.CreateProgramA()));
Container.Register(Component.For<RunnerService>().AsWcfService());

这是我的Factory(所有依赖项实现相同的接口,所有SubDependencies实现其他共享接口):

public static class Factory{
  public static IValidationProgram CreateProgramA(){
    var program = new ValidationProgram(
       new DependencyA(
         new SubDependencyA(),
         new SubDependencyB(),
       ),
       new DependencyB()
    );
  }
}

在我的RunnerService IExecutionProgram中,属性将被解析。 在我的IValidationProgram中,我创建的IExecutionProgram将无法解析。 属性在两个实现中都是公共的。 我做错了什么?

修改 我加了工厂。这些依赖项都是接口,我需要一个程序的特定实现。所以一般来说我想在programA或programB之间轻松切换。我看着像Marwijn所说的类型设施,但我无法掌握它。我如何在我的案例中使用它?

0 个答案:

没有答案