title: MEF problem with import
body: <p>models from shell-view-model with abstract factory pattern. I need inject in view-models classes from external assembly. If I use abstract factory pattern on creation view-models. Problem is imported classes in view-models are null.</p>
  
  <p>Shell-view-models look like this:</p>
  
  <pre><code>public interface IViewModelFactory
      {
          ILogOnViewModel CreateLogOnViewModel(IShellViewModel shellViewModel);
          IMessengerViewModel CreateMessengerViewModel(IShellViewModel shellViewModel);
      }
  
      [Export(typeof(IViewModelFactory))]
      public class DefaulFactoryViewModel:IViewModelFactory
      {
          #region Implementation of IViewModelFactory
  
          public ILogOnViewModel CreateLogOnViewModel(IShellViewModel shellViewModel)
          {
              return  new LogOnViewModel(shellViewModel);
          }
  
          public IMessengerViewModel CreateMessengerViewModel(IShellViewModel shellViewModel)
          {
              return new MessengerViewModel(shellViewModel);
          }
  
          #endregion
      }
  
  
      public interface IShellViewModel
      {
          void ShowLogOnView();
          void ShowMessengerView();
      }
  
      [Export(typeof(IShellViewModel))]
      public class ShellViewModel : Conductor&lt;IScreen&gt;, IShellViewModel
      {
  
          private readonly IViewModelFactory _factory;
  
          [ImportingConstructor]
          public ShellViewModel(IViewModelFactory factory)
          {
              _factory = factory;
              ShowLogOnView();
          }
  
          public void ShowLogOnView()
          {
              var model = _factory.CreateLogOnViewModel(this);
              // var model = IoC.Get&lt;LogOnViewModel&gt;();
              ActivateItem(model);
          }
  
          public void ShowMessengerView()
          {
              var model = _factory.CreateMessengerViewModel(this);
              ActivateItem(model);
          }
      }
  </code></pre>
  
  <p>Some view-model.:</p>
  
  <pre><code>public class LogOnViewModel : Screen,ILogOnViewModel
  {
      [Import]//inject class from external assembly
      private IPokecConnection _pokecConn;
  
      private readonly IShellViewModel _shellViewModel=null;
  
      private User _user=null;
  
      public LogOnViewModel(IShellViewModel shellViewModel)
      {
          _shellViewModel = shellViewModel;
          _user = new User();
      }
  }
  </code></pre>
  
  <p>variable _pokecConn are null becasuse I use abstract factory on creation new view-models.</p>
  
  <p>if I use in shell-view model this:</p>
  
  <pre><code>var model = IoC.Get&lt;LogOnViewModel&gt;();
  </code></pre>
  
  <p>instead this:</p>
  
  <pre><code>var model = _factory.CreateLogOnViewModel(this);
  </code></pre>
  
  <p>and add Export attribute on view-models classes it works good, but I would like use abstract factory, and inject in view-model only classes from extrenal assembly.
  It exist solution on this problem, or I must create view-models from IoC and export all class? Thanl for advance.</p>
  
  <p><strong>EDITED :</strong></p>
  
  <p>MEF BOOTSTRAPER CLASS:</p>
  
  <pre><code> public class MefBootStrapper : Bootstrapper&lt;IShellViewModel&gt;
      {
      #region Fields
      private CompositionContainer _container;
      #endregion
  
      #region Overrides
      protected override void Configure()
      { //  configure container
      #if SILVERLIGHT
          _container = CompositionHost.Initialize(
          new AggregateCatalog(AssemblySource.Instance.Select(x =&gt; new AssemblyCatalog(x)).OfType&lt;ComposablePartCatalog&gt;()));
      #else
  
          var catalog =
              new AggregateCatalog(
                  AssemblySource.Instance.Select(x =&gt; new AssemblyCatalog(x)).OfType&lt;ComposablePartCatalog&gt;());
  
          //add external DLL
          catalog.Catalogs.Add(
              new AssemblyCatalog(string.Format(
                  CultureInfo.InvariantCulture, "{0}{1}", System.IO.Directory.GetCurrentDirectory(), @"\Pokec_Toolkit.dll")));
  
          _container = new CompositionContainer(catalog);
      #endif
  
          var batch = new CompositionBatch();
  
          batch.AddExportedValue&lt;IWindowManager&gt;(new WindowManager());
          batch.AddExportedValue&lt;IEventAggregator&gt;(new EventAggregator());
          batch.AddExportedValue(_container);
  
          _container.Compose(batch);
          _container.SatisfyImportsOnce(this);  
      }
  
      protected override object GetInstance(Type serviceType, string key)
      {
          string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
          var exports = _container.GetExportedValues&lt;object&gt;(contract);
  
          if (exports.Count() &gt; 0)
          return exports.First();
  
          throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
      }
  
      protected override IEnumerable&lt;object&gt; GetAllInstances(Type serviceType)
      {
          return _container.GetExportedValues&lt;object&gt;(AttributedModelServices.GetContractName(serviceType));
      }
  
      protected override void BuildUp(object instance)
      {
          _container.SatisfyImportsOnce(instance);
      }
      #endregion
      }
  </code></pre>