0
votes

I seem to have a chicken-before-the-egg problem in my Prism/WPF app with regards to bootstrapping workflow.

How does one register components in the IoC container, when that registration depends on user options, and those user options need to be collected at startup, which requires a UI workflow, which requires services which are resolved from the container, which requires the container to be already configured?

It seems like a paradox. But ok, I guess I could break up my container registration into two phases, and have a startup procedure like this:

  1. Kick-off PRISM Bootstrapper (e.g. UnityBootstapper) and create the container
  2. Register components required by the startup workflow
  3. Show UI dialog workflow and collect user options/settings
  4. According to the settings just collected, register the remaining application components in the container
  5. Let the CreateShell() and InitializeShell() do their typical thing and resolving the shell window and showing it.

This seems like it should work OK. However, I get the feeling that there has to be a better way. Should the shell (even just a placeholder with a title bar and nice wallpaper image) be shown first, with the startup workflow dialog be shown over top? Of course that implies that there must be a 2nd phase of container registration after the shell is created... which now seems even further from PRISM standards.

Some best-practices in either PRISM or WPF/MVVM in general would be much appreciated.

1

1 Answers

0
votes

I'd say this is more a problem of dependency injection than with a particular framework.

Consider this:

you have some UI ViewModel

public class SomeUIVM
{
   ctor(IDependency iNeedThis){...}
}

And you need a selection from the user if he wants class DepA : IDependency or class DepB : IDependency.

Rework your setup by having this class registered at startup:

public class SpecificDependencyProvider : IDependencyProvider
{
  public IDependency SelectedDependency {get;set;}
}

so then SomeUIVM's constructor takes a IDependencyProvider and accesses the SelectedDependency property. The Selection UI also takes that IDependencyProvider and sets the SelectedDependency.