-
-
Notifications
You must be signed in to change notification settings - Fork 144
Bootstrapper
The bootstrapper is responsible for bootstrapping your application. It configures the IoC container, creates a new instance of your root ViewModel and displays it using the WindowManager
. It also provides various other functions, described below.
The bootstrapper comes in two flavours: BootstrapperBase<TRootViewModel>
, which requires you to configure the IoC container yourself, and Bootstrapper<TRootViewModel>
, which uses Stylet's built-in IoC container, StyletIoC.
Example bootstrapper, using StyletIoC:
class Bootstrapper : Bootstrapper<MyRootViewModel>
{
protected override void OnStart()
{
// This is called just after the application is started, but before the IoC container is set up.
// Set up things like logging, etc
}
protected override void ConfigureIoC(IStyletIoCBuilder builder)
{
// Bind your own types. Concrete types are automatically self-bound.
builder.Bind<IMyInterface>().To<MyType>();
}
protected override void Configure()
{
// This is called after Stylet has created the IoC container, so this.Container exists, but before the
// Root ViewModel is launched.
// Configure your services, etc, in here
}
protected override void OnLaunch()
{
// This is called just after the root ViewModel has been launched
// Something like a version check that displays a dialog might be launched from here
}
protected override void OnExit(ExitEventArgs e)
{
// Called on Application.Exit
}
protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
{
// Called on Application.DispatcherUnhandledException
}
}
Using another IoC container with Stylet is easy. I've included bootstrappers for a number of popular IoC containers in the Bootstrappers project. These are all unit-tested but not battle-tested: feel free to customize them.
Note that the Stylet nuget package / dll don't include these, as it would add unnecessary dependencies. Similarly, I don't publish IoC container-specific packages, as that's a waste of effort. Just copy the bootstrapper you want from the above link into your project.
If you want to write your own bootstrapper for another IoC container, that's easy too. Take a look at the bootstrappers above to see what you need to do.
- Introduction
- Quick Start
- Bootstrapper
- ViewModel First
- Actions
- The WindowManager
- MessageBox
- The EventAggregator
- PropertyChangedBase
- Execute: Dispatching to the UI Thread
- Screens and Conductors
- BindableCollection
- Validation using ValidatingModelBase
- StyletIoC
- The ViewManager
- Listening to INotifyPropertyChanged
- Design Mode Support
- Logging
- Misc