In my App.xaml.cs I have
private void InitializeContainer()
{
var catalogs = new AggregateCatalog();
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
catalogs.Catalogs.Add(catalog);
// Also adding Interactions project
catalog = new AssemblyCatalog(typeof(InteractionsService).Assembly);
catalogs.Catalogs.Add(catalog);
// initialize the main application composition host (container)
CompositionHost.Initialize(catalogs);
}
However, when I try to get object initialized down a line like so:
this.InteractionsService = ServiceLocator.Current.GetInstance<IInteractionsService>();
I get exception that my ServiceLocator.Current is null.
How do I make it work?
I think you’re missing the call to
ComposePartsorComposein the set up of theCompositionContainer. Before you start to resolve instances viaGetInstance.There’s an MSDN walk through here, and some other samples here and here. The relevant code snippet: