How to prevent Castle Windsor from injecting property dependencies?

别来无恙 提交于 2019-12-11 02:13:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!