I'm trying to determine the best way to reuse back-end business modules in an existing web application.
The UI for this application is pretty straight forward:
- Form on first page collects a handful of options,
- on submit it gets stuffed into the session and
- the target process takes this information, does some processing using this information (calls external services, retrieves database information, etc.) and conditionally generates some business objects,
- stuffs this into the session and then
- passes this along to the centralized back-end driver.
- This driver now accesses the objects in the session for initialization purposes. So currently this driver is dependent on the web session service for providing these items.
I want to re-purpose this driver for a command-line interface. So these options from the initial web page can instead be passed in as args to an entry point that then performs the steps from 3 on.
Ideally I would like to use the same modules for both the web and standalone applications in order to avoid code duplication, but the dependency on the web session object, and how to decouple this is a head scratcher.
I was hoping I might be able to "spoof" a web session in the standalone version, but if not running within the context of an http client I'm pretty sure this isn't possible?
Outside of this I was thinking that I would have to pull session stuff out of the code entirely and using some other mechanism for passing data around, this wouldn't be an easy task, lots of modules would have to touched as a result.
Other then generating an entirely separate branch of code (which I'm afraid I'm pretty much going to have to do) or a wholesale restructuring of the code base, any suggestions on any relatively lightweight alternatives?