MEF and the IWindowManager

Jan 27, 2011 at 10:50 AM

I having problems discovering the IWindowManger when using the Mef Adapter.

this doesn't work

var someViewModel = ServiceLocator.Current.GetInstance<ISomeViewModel>();

****

[PerRequest(typeof(ISomeViewModel))]
    public class SomeViewModel: ISomeViewModel
    {
//Contructor
public  SomeViewModel(IWindowManager windowManager, ISomeOtherViewModel someOtherViewModel)
{...

though this will work when using the simple container.

 

is there anything in the configuration i need to do to get this working?

 

cheers,

Coordinator
Jan 27, 2011 at 12:43 PM

Two questions: What version are you using? Can you show me your configuration?

Jan 27, 2011 at 3:08 PM

Hi

 

I'm using version 1.1.0.49753 of Caliburn

and MEF shipped with the .Net 4 framework

 

 public App()
        {
            
            
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            this.InitializeComponent();
            CaliburnFramework
                .ConfigureCore()
                .WithAssemblies(Assembly.GetExecutingAssembly())
                .Start();
        }

protected override IServiceLocator CreateContainer()
        {
            var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            _container = new CompositionContainer(catalog);
            return new MEFAdapter(_container);
        }

        protected override object CreateRootModel()
        {
            var binder = (DefaultBinder)Container.GetInstance<IBinder>();

            binder.EnableMessageConventions();
            binder.EnableBindingConventions();

            return this._container.GetExportedValue<IShellViewModel>();
        }

I was able to get around it via a Factory pattern and no longer Discovering object through the ServiceLocator like in the intial post.

Though Interest to no why it stopped working.

Also one question would it be possible to Import the caliburn Default Window Manager?

[Export(typeof(ISomeObject))]
public class SomeObject : ISomeObject
{
     [Import(typeof(IWindowManager))]
     public IWindowManager WindowManager { get; set; }
}


Cheers,

the Haggis.

Coordinator
Jan 27, 2011 at 3:44 PM

You are not enabling the presentation framework in the configuration:

             CaliburnFramework
                .ConfigureCore()
                .WithAssemblies(Assembly.GetExecutingAssembly())
                .WithPresentationFramework()
.Start();

 

Jan 27, 2011 at 3:58 PM

how very silly of me.

thanks again.