views:

167

answers:

1

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?

+2  A: 

How about:

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

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

Mauricio Scheffer
thanks mausch that worked... wish I could get my heard around the registration syntax, problem is I don't use it enough.
Hainesy

related questions