Bootstrap Serialization

Oct 16, 2010 at 4:50 PM
Edited Oct 16, 2010 at 4:51 PM

Currently we create the Bootstrap in Xaml (where I believe it should be, indeed).  Previously, with the CaliburnApplication, we could specify application-specific properties in the App.xaml and force a call to InitializeComponent in the BeforeConfiguration override to ensure the Application was properly serialized before continuing.

Now, with the Bootstrap, I am finding it impossible ensure serialization of this object before SelectAssemblies is called.  This is how I initialize my application:

  • Define all my IoC registrations in Xaml through the use of a UnityApplicationContainer object (it holds all my registrations and instances in Xaml).
  • Ensure Xaml is serialized.
  • Create the container.
  • Get the reference to a IAssemblyRegistry to retrieve all assemblies used for the application (also defined in Xaml :) :) :)).

This would actually work if the Bootstrapper initialization code was called from a Dispatcher.BeginInvoke from the Bootstrapper constructor.  However, the initialization code gets called *after* the application startup event.  Blah.

In any case, I'm wanting to bring awareness to this scenario/mindset, and get feedback on how I should change my thinking. ;)  I am a big believer in Xaml and want to ensure I place as much of my application in Xaml as possible (for easier maintenance and configuration).

Oct 16, 2010 at 7:52 PM

The point of boostrapper is to allow the framework to start even when running in designer, thus preserving "Blendability" of the project.
Since Xaml cannot explicitly call an Init method, all startup code have to run in the bootstrapper constructor.
To achieve the correct sequence of operations, you might:
- use a custom bootstapper calling App.InitializeComponents in the constructor
- override Bootstrapper.SelectAssemblies and call App.InitializeComponents there: REALLY unelegant, but it's the first overridable call in the startup sequence

Oct 16, 2010 at 8:37 PM

Hm.  I haven't even gotten to Blend yet, LOL.  I ended up using a custom application object with a Bootstrapper and ServiceLocatorProvider property, and have the two using each other.  Kinda unelegant as you say, but it gets the job done for now.  I'm sure another solution will work itself out in the future.

Oct 17, 2010 at 4:56 AM

I should point out that the bootstrapper is really there for convenience. There's no reason you "have to" use it. Just take the code from it, tear it apart and make it work for your scnenario. You basically just need to make sure your IoC gets setup, the dispatcher is prepared and that you provide your assemblies list to CM. Finally, you need to set up your root vm/view.

Oct 17, 2010 at 11:13 AM

Mmm... I appreciate that, but if anything does change in the initialization process, then I'll have to keep an eye on the bootstrapper to make sure I'm in sync.  And I'd just rather use it and stay in the fold rather than going off on my own wacky version.