9.22 Forwarded Types

优质
小牛编辑
133浏览
2023-12-01

Forwarded types are additional services exposed by a component. For example, given the following component:

public class FooBar : IFoo, IBar
{
    public void DoFoo()
    {
        // some implementation
    }

    public void DoBar()
    {
        // some implementation
    }
}

Windsor will let you expose this single component as both IFoo and IBar service.

//register FooBar as both IFoo and IBar with singleton lifestyle

var foo = container.Resolve<IFoo>();
var bar = container.Resolve<IBar>();

Debug.Assert(object.ReferenceEquals(foo, bar));

This can be done either via fluent registration API or XML configuration.