Import/Export from .dll

Mar 1, 2013 at 6:43 PM
I am trying to create my own extended .dll to use with all my WinRT apps, but I'm having trouble with MEF.
For instance, in My.dll, I have a IMyService interface and a MyService class which implements it. I tag the MyService class with the [Export(typeof(IMyService))] and [Shared] tags.

Then, I have a Bootstrapper.cs class that inherits the OkraBootstrapper where I [Import] IMyService.

Now I build My.dll and add it as a reference in a new project, call it MyApp. I create a new class called AppBootstrapper.cs that inherits from the Bootsrapper in my dll.

After I create the AppBoostrapper property in App.xaml.cs, set it to a new AppBoostrapper(), then Initialize it, it fails on Initialize. Error:

CompositionFailedException - Missing dependency 'MyService' on 'MyApp.AppBoostrapper'

at System.Composition.CompositionContextExtensions.SatisfyImportsInternal(CompositionContext exportProvider, Object objectWithLooseImports, AttributedModelProvider conventions)
at System.Composition.CompositionContextExtensions.SatisfyImports(CompositionContext compositionContext, Object objectWithLooseImports)
at Okra.OkraBootstrapper.Initialize(Boolean registerForActivation)
at Okra.OkraBootstrapper.Initialize()
at MyApp.App..ctor() in d:\code\MyApp\App.xaml.cs:line 23
at MyApp.<Main>b__0(ApplicationInitializationCallbackParams p) in d:\code\MyApp\obj\Debug\App.g.i.cs:line 23

I'm not sure how to troubleshoot this. I was looking into the Okra framework and how it's don't there, but I can't find what I'm doing different. Any advise?
Mar 1, 2013 at 6:59 PM
Never mind. Of course right after I post a light bulb goes on. In my Bootsrapper class I had to override the OkraBootstrapper.GetContainerConfiguration and add my assembly to it. Easy enough to do:
    return base.GetContainerConfiguration().WithAssembly(typeof(IMyService).GetTypeInfo().Assembly);
Mar 2, 2013 at 9:38 AM
Pleased you got this sorted. I've done this in the past as well and wondered for a while why it wouldn't compose!