Bootstrapping nRoute is quite easy in Silverlight, all one needs to do is add an nRouteApplicationService instance in the Application’s ApplicationLifetimeObjects collection. So in app.xaml we could do something like:
<Application ... xmlns:n="http://nRoute/schemas/2010/xaml">
Alternatively, you could also do the same via code-behind, but declaring it in xaml is generally the preferred approach as you don’t need to deal with lifetime issues.
Within Silverlight the ApplicationLifetimeObjects collection is a special mechanism for
extending the Silverlight application model, as it provides hooks into the application lifetime events via IApplicationService and optionally the IApplicationLifetimeAware interfaces.
However, in WPF there is nothing equivalent to Silverlight’s ApplicationLifetimeObjects – which is a shame as it is a simple but powerful approach to extending application-level infrastructure.
So as to provide the equivalent mechanism for bootstrapping in WPF, we’ve provide a derived Application class that introduces ApplicationLifetimeObjects in WPF. This not only allows nRoute, but any custom IApplicationService derived services to hook into
WPF’s application model just like in Silverlight. With our custom Application class in WPF the app.xaml equivalent would look like:
<n:Application ... xmlns:n="http://nRoute/schemas/2010/xaml"
Additionally, one would need to inherit from nRoute’s custom Application type in the code-behind too:
public partial class App : nRoute.ApplicationServices.Application
If nRoute is not bootstrapped you’ll run into exceptions stating that the nRouteApplicationService has not initialized, similarly, if you try to initialize the service twice it will also raise an exception. You can check if nRoute service has initialized
via nRouteApplicationService’s “IsInitialized” static property.