I've just refactored out a new domain class from a presenter class but I can't figure out where to instantiate it.
This is part of a larger ongoing refactoring effort with a poorly maintained legacy project.
The Presenter is currently being created by the view's OnLoad event and the view is passed as a parameter in the constructor. All public methods in the presenter are parameterless and return void. They communicate with the view using public properties of the view.
The view, being essentially a humble form depends entirely on the presenter for everything.
This is the typical Passive View pattern and I'd like to continue to adhere to it. Which brings me to my dilemma. I need to create an instance of my new domain object for the presenter to use.
- If I pass it through the constructor then the view has to create it and gains an unnecessary dependency.
- If I create it anywhere within the presenter, I can't replace it with a mock object in my unit tests.
- If I make it a public property of the presenter then I introduce a creation order dependency on the presenter methods where it is used and I still haven't solved what external class gets responsibility for creating it.
I am not currently using any dependency injection frameworks. While I'm interested it using one in the future the source code is still much to fragile to introduce a third party framework into the mix.
I'm open to any suggestions.