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 be开发者_C百科cause 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.
精彩评论