Windsor Container: How to specify a public property should not be filled by the container?

后端 未结 7 1912
小鲜肉
小鲜肉 2021-01-01 23:32

When Instantiating a class, Windsor by default treats all public properties of the class as optional dependencies and tries to satisfy them. In my case, this creates a rath

7条回答
  •  Happy的楠姐
    2021-01-01 23:49

    This can be achieved by the following code:

    var container = new WindsorContainer();
    
    // We don't want to inject properties, only ctors
    var propInjector = container.Kernel.ComponentModelBuilder
                             .Contributors
                             .OfType()
                             .Single();
    container.Kernel.ComponentModelBuilder.RemoveContributor(propInjector);
    

    Source Castle Windsor Documentation

提交回复
热议问题