c# - How to initialize MEF ServiceLocator.Current? -



c# - How to initialize MEF ServiceLocator.Current? -

in app.xaml.cs have

private void initializecontainer() { var catalogs = new aggregatecatalog(); var catalog = new assemblycatalog(assembly.getexecutingassembly()); catalogs.catalogs.add(catalog); // adding interactions project catalog = new assemblycatalog(typeof(interactionsservice).assembly); catalogs.catalogs.add(catalog); // initialize main application composition host (container) compositionhost.initialize(catalogs); }

however, when seek object initialized downwards line so:

this.interactionsservice = servicelocator.current.getinstance<iinteractionsservice>();

i exception servicelocator.current null.

how create work?

i think you're missing phone call composeparts or compose in set of compositioncontainer . before start resolve instances via getinstance.

there's msdn walk through here, , other samples here , here. relevant code snippet:

private compositioncontainer _container //your code var batch = new compositionbatch(); batch.addpart(this); _container.compose(batch); //or more _container.composeparts(this) //if method supported

c# silverlight mef

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -