Background
I'm using Castle Windsor as my IOC container in a WPF application. In this application, the user can open a single project file, which is modeled using a concrete version of an IProjectModel
interface. So, at any given time there is zero or one instance(s) of IProjectModel
available. I'm currently defining the lifestyle of its implementor as transient, and this implementor expects in its constructor a filename as a string
which is chosen by the user (from a dialog). The IProjectModel
instance is resolved via a typed factory interface, e.g.:
public interface IProjectModelFactory
{
IProjectModel Create(string fileName);
}
Question
I initially figured it was bad to treat it as a singleton since:
- it is transient with respect to the application lifetime;
- it has dependencies of its own, i.e. the filename (
string
) to open, that I don't think I could specify if it had singleton/scoped lifestyle; - passing it around keeps open the option of having multiple projects open at once.
However, now that I'm creating factory after factory in order to pass the current IProjectModel
instance around I'm somewhat regretting that decision. It'd be much easier to have the container hand my objects the current project model, rather than pass it down from way up the object chain.
How is a situation like this supposed to be handled using Castle Windsor?
It seems like the Scoped Lifestyle is built for this (the scope is the currently open project/file name), but I can't figure out how to get information about the opened file into the IScopeAccessor
since I can't inject anything into that.