I have to support a new input file format in a system which uses Windsor. I also need to support the old version of the input file during a transition phase.
This will probably be repeated in future, and we’ll again need to support the new and the next most recent format.
The import processing is handled by a component, and the new version has had significant improvements in the code which makes it lots more efficient compared to the old version. So what I’d like to do is to have the new component and the old component in the system, and dynamically use the new or the old component based upon the file metadata.
Is there a pattern for this type of scenario anyone can suggest?
The fact that you’re using Windsor is pretty much irrelevant here. Always strive to find a container-independent solution. Here’s one:
Your app would take a dependency on
IImportProcessor. The container is wired so that the default implementation of this interface isMainImportProcessor. The container is also wired so thatMainImportProcessorgets all other implementations ofIImportProcessor.This way you can add implementations of
IImportProcessorand each will be selected when appropriate.It might be easier to wire things up if
MainImportProcessorimplements an interface different fromIImportProcessor.Another possibility could be implementing a chain of responsibility.