Reputation: 5632
I thought about trying to learn caliburn again. First few lessons were easy but things get complicated as I progressed and I cannot figure it out alone.
I designed an app for the purpose to cover most of the basics which have a ShellViewModel of type Conductor<IScreen>
and a few ChildViews which implements IScreen
.I'm using an IOC container to compose ViewModels and related resources in the App.
One of the child is like a Navigation Desk from which user can access different child views and those child views support navigation to one or two other views also.
When I looked for samples introducing the concept of Screen and conductors, all those samples directly created and activated the viewmodels by calling ActivateItem(new ChildViewModel())
, may be for the sake of simplicity, but I'm having trouble understanding how these viewmodel creation can be delegated to IOC container without having a dependency on it.
For one or two screens atleast I can inject via constructor, but what about when there are a lot of views to which, user can navigate from any given view and each of them have additional dependencies of their own?
Forgiving the dumbness of a beginner, Can anyone point me in the right direction?
Upvotes: 2
Views: 434
Reputation: 34349
You want to use view model factories, which have a dependency on your IoC container. For example, your ShellViewModel could take an IViewModelFactory which has methods for CreateNavigatorViewModel etc which returns an NavigatorViewModel (or INavigatorViewModel), and this implementation uses the IoC container to resolve I/NavigatorViewModel.
Some IoC containers support automatic creation of these factories, for example Castle.Windsor has a Typed Factory Facility, and Ninject has an extension which creates factory types, you just define the factory interface.
Upvotes: 2