How do I configure a single component instance providing multiple services in Castle.Windsor?

女生的网名这么多〃 提交于 2019-12-05 07:58:41
Steven Lyons

Have you checked out the answer to this question (especially the forum post link) that appears to be what you are looking for. Some of the examples are using the Transient lifecycle but I think it will work with Singleton also.

The main pay-off of the forum post is:

container.Register(Component.For<IEntityIndexController, ISnippetController>()
.ImplementedBy<SnippetController>()
.LifeStyle.Transient); 

The solution is uses the fluent interface (and a recent trunk build) and it wasn't possible to configure in xml last I saw. However, it may be possible with a facility.

Good luck!

Have you tried using the Forward method:

container.Register(Component.For<IEntityIndexController>()
.ImplementedBy<SnippetController>()
.Forward (typeof(ISnippetController))
.LifeStyle.Transient);

From my experiments and from the documentation:

register the service types on behalf of this component

i think it shoud do the trick.

jishi

You can register an instance of an object (instead of an implementation) to be responsible for different implementations:

  var ab = new AB();
  container.Register( Component.For<IA>().Instance( ab) );
  container.Register( Component.For<IB>().Instance( ab) );

I believe that should work. However, that requires in code configuration, for apparent reasons.

I was searching for the same answer, and this post is the farthest I could get with google. I found that using

Classes.FromThisAssembly().Where(t => t.FullName == "Namespace.Classname").WithServiceAllInterfaces()

Seems to do the trick for me.

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