CompositionHost in WPF?

Topics: Bootstrappers & IoC
Nov 29, 2011 at 7:51 PM

I am trying to learn how Caliburn works, trying to replicate the GameLibrary app in WPF.

The CompositionHost does not seem to exist in WPF and so I am wondering how that part of the bootstrapper is supposed to work in WPF.

I can't find anything about this and I am not even sure what it does, so it is hard to figure a way around it.

Thank you,

Richard

Coordinator
Nov 30, 2011 at 1:54 AM

You can just get rid of that. ComposisitionHost was something the MEF did for Silverlight to make it easier to get a container up and running and so control vendors could leverage MEF.

Just instantiate a CompositionContainer directly.

Dec 5, 2011 at 8:09 PM

Hm I don't know hot to work it still.

Where can I learn about these Exports/Imports/ImportingConstructor decorators for the sake of using caliburn?

Can we make the GameLibrary without these bits of composition or would that be missing the point?

Dec 6, 2011 at 7:43 AM

You dont have to use MEF. If you are more familiar with another IoC Container/DI Framework (Castle.Windsor, Ninject, Lightcore,...) use that. If you dont know about any of those concepts yet you should prolly learn about them first. The MEF Docu gives a short introduction http://mef.codeplex.com/wikipage?title=Overview&referringTitle=Documentation or read fowlers article http://martinfowler.com/articles/injection.html

Jan 2, 2012 at 10:34 AM

Richard

I am familir with structure map and about to move to autofac because of its support for windows phone and silverlight.

Right now I prefer them over MEF because they use simple c# code , easy to configure unlike MEF which uses a lot of attributes etc.

However to keep things as standard as possilbe decided to use MEF for Caliburn Micro and will use my autofac inside my Models.

Yes and it would be nice if somebody could approve an 'official' autofac bootstrapper for WPF, Silverlight and Windows Phone, because I have seen about 3 versions on the internet. Last thing I need learning a new framework is having bugs as a result of yet other plugins.

So I am not familiar with MEF, however based on Rob EisenBergs reply, I tried the following and please anybody correct me if i am wrong:

in Configure method replace:

container = CompositionHost.Initialize(( new AggregateCatalog ( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog >() ));

with :

container =new CompositionContainer (  new AggregateCatalog (  AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog >() ));

..

it compiles as a first step..will keep posted if gives issues.

 

Jan 4, 2012 at 5:30 PM

thank you gregor