Castle Windsor quotNo converter registered to handle the typequot
If you have an object that has a property of some type that is not known by windsor (as example Regex), if you try to configure it with xml the error “No converter registered to handle the type” will occurs. This happens because the container read configuration as string, and then it has to convert to a type it does not know. The solution is to write few line of code to create a converter
|
|
A converter has three methods, the first CanHandleType is called to check if this converter can handle various type. In our implementation I return true only if the type is a Regular Expression. The remaining two methods PerformConversion are called to actually perform the desidered conversion. In our situation the conversion is straightforward because you can simply use the constructor of the Regex that accepts a string.
To register this converter into the container you need to use these snippet
|
|
You get the IConversionManager by Kernel.GetSubSystem, and then add your new converter…the game is done.
alk.
Tags: Castle Windsor Converters