Markus Dulghier
Markus Dulghier

Reputation: 1580

How to prevent Castle Windsor from injecting property dependencies?

Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties (besides the [DoNotWire] attribute)?

Upvotes: 2

Views: 2842

Answers (2)

Jan Palas
Jan Palas

Reputation: 1895

If you want to turn off property injection globally, you can use this code:

// We don't want to inject properties, only ctors
var propInjector = Kernel.ComponentModelBuilder
                     .Contributors
                     .OfType<PropertiesDependenciesModelInspector>()
                     .Single();

Kernel.ComponentModelBuilder.RemoveContributor(propInjector);

(Code sample taken from Castle Windsor docs - refer for further details)

Upvotes: 1

Related Questions