你如何使用Castle Windsor - Fluent Interface来注册通用接口?

Phi*_*hil 8 c# castle-windsor fluent-interface castle ioc-container

Castle Windsor刚刚推出了一个用于注册组件的Fluent接口,作为在配置文件中使用XML的替代方法.如何使用此Fluent界面注册Generic界面

为了说明,我有:

public interface IFoo<T,U>
{    
  public T IToo();   
  public U ISeeU(); 
}
Run Code Online (Sandbox Code Playgroud)

这是由一个名为Foo的类实现的.现在,如果我想注册这个,我会做...

var _container = new WindsorContainer();
_container.Register(...);
Run Code Online (Sandbox Code Playgroud)

如何进行注册?执行非通用接口的过程不起作用.

dan*_*iax 15

喜欢这样吗?

   container.Register(AllTypes.FromAssemblyContaining<YourClass>()
        .BasedOn(typeof(IFoo<,>))
        .WithService.AllInterfaces()
        .Configure(c => c.LifeStyle.Transient));
Run Code Online (Sandbox Code Playgroud)

接口

 public interface IFoo<T, U>
{
    T IToo();
    U ISeeU();
}
Run Code Online (Sandbox Code Playgroud)