English 中文(简体)
Castle Windsor auto registration
原标题:

I currently have the following registration set up

private static void AddFrameworkComponentsTo(IWindsorContainer container)
{
    container.AddComponent<ITypeConverter, TypeConversionFacade>();
    container.AddComponent<Framework.Conversion.ITypeConverter<string, int>, StringConverter>();
    container.AddComponent<Framework.Conversion.ITypeConverter<string, decimal>, StringConverter>();
    container.AddComponent<Framework.Conversion.ITypeConverter<string, DateTime>, StringConverter>();
}

What s the easiest way to avoid having to register each interface to the same component? As you can see, my "StringConverter" class implements several different interfaces, and the list is likely to grow.

Edit I ve just realised that the above doesn t even work because complains about the key, so had to change it to below:

container.AddComponent<Framework.Conversion.ITypeConverter<string, int>, StringConverter>("ITypeConverter<string, int>");
container.AddComponent<Framework.Conversion.ITypeConverter<string, decimal>, StringConverter>("ITypeConverter<string, decimal>");
container.AddComponent<Framework.Conversion.ITypeConverter<string, DateTime>, StringConverter>("ITypeConverter<string, DateTime>");

What s the best way to handle this?

最佳回答

How about:

container.Register(Component.For(typeof(StringConverter).GetInterfaces())
                            .ImplementedBy(typeof(StringConverter)));

See the fluent API wiki for more information on fluent registration.

问题回答

暂无回答




相关问题
castle IOC - resolving circular references

quick question for my MVP implementation: currently I have the code below, in which both the presenter and view are resolved via the container. Then the presenter calls View.Init to pass himself to ...

Castle Windsor auto registration

I currently have the following registration set up private static void AddFrameworkComponentsTo(IWindsorContainer container) { container.AddComponent<ITypeConverter, TypeConversionFacade>();...

Authorization and Windsor

I m trying to implement my custom authorize attribute like: public class MyCustomAuth : AuthorizeAttribute { private readonly IUserService _userService; public MyCustomAuth(IUserService ...

How can I override a component registered in Castle Windsor?

I m just starting with Windsor, so please be gentle :) I have a scenario where I want to be able to override/replace components placed inside a windsor container. Read on ... In my prod code, I want ...

热门标签