问题
Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties (besides the [DoNotWire] attribute)?
回答1:
Duplicate: Windsor Container: How to specify a public property should not be filled by the container?
See also:
- http://groups.google.com/group/castle-project-users/browse_thread/thread/f1ec737ff243c19d
- http://jfromaniello.blogspot.com/2009/07/noninjectable-service.html
- http://using.castleproject.org/display/Contrib/Castle.Facilities.OptionalPropertyInjection
回答2:
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)
来源:https://stackoverflow.com/questions/1359336/how-to-prevent-castle-windsor-from-injecting-property-dependencies