Exporting Property on Application Object

Sep 9, 2010 at 4:08 PM
Edited Sep 9, 2010 at 4:09 PM

Hello all,

I'm currently knee-deep in my first real adventure into Composition. 

I have a property on my Application (WPF) object that I'm trying to export.  The property has an ExportAttribute assigned to it and everything is configured correctly.  However, when the container tries to resolve the export, the following exception is thrown:

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) Cannot create more than one System.Windows.Application instance in the same AppDomain.

Is there a way to tell the Export attribute to use the Application.Current property when resolving the Application object required for the Export?

Thanks for any assistance you can provide!

Michael

Sep 11, 2010 at 12:23 AM

Hi Michael,

I am MEF beginner but it does strike me as somewhat unusual to want to export an Application property. Application object, along with its properties, is available from anywhere within that very Application, so what does export accomplish in this case?

See if you get a different result when you designate that property as shared (add on top of export attribute):

[PartCreationPolicy(CreationPolicy.Shared)]

 

 

Sep 11, 2010 at 12:41 AM
Hi Michael

To export the application use a property export...it can be on the application class itself as we support static exports

public class MyApplication : App {
[Export]
public static Application AppExport { get {return Application.Current;}}
}

Also see my blog post on property exports.,,

Sent from my IPad.

On Sep 10, 2010, at 5:24 PM, "Tonko" <notifications@codeplex.com> wrote:

From: Tonko

Hi Michael,

I am MEF beginner but it does strike me as somewhat unusual to want to export an Application property. Application object, along with its properties, is available from anywhere within that very Application, so what does export accomplish in this case?

See if you get a different result when you designate that property as shared (add on top of export attribute):

[PartCreationPolicy(CreationPolicy.Shared)]