I have a desktop application I wish to migrate to Spring (3.0.5) which involves "steps" where user decisions are needed before certain objects (or beans) can be instantiated.
Hypothetical example: Suppose the application allows the user to convert mailboxes from a mail-reader program.
- User picks a directory,
- Application analyzes a meta-data file in directory
- User picks a file from a provided selection of valid "mailbox" files
- Application analyzes source file details to determine appropriate default output settings
- User customized destination directory and output settings
- Application does conversion and saving
From what I can tell it seems there are a few options for ways to handle this in Spring:
- Create a set of nested (parent/child)
ApplicationContext
objects as the necessary pieces of information arrive. - Create some "data holding" beans, and rely on simply not calling certain code-paths while they might be "empty". Ex: If I have a
WriteToFile
bean which needs aFile
destination chosen by the user, re-factor it to instead require aFileHolder
which is interrogated wheneverWriteToFile.go()
is called. - Use some combination of
lazy-init
,scope="prototype开发者_高级运维"
, andMethodInvokingFactoryBean
so that "later" beans are lazily-initialized only when the source information (on other beans) is available.
Do any of those seem better than the others? Am I missing an option?
Right now #3 with perhaps a little bit of #1 sounds preferable.
精彩评论