Registering Instances

Dec 19, 2008 at 4:28 PM
Does MEF have a story for registering or caching instances once they're resolved? The ability to register instances makes Unity exceptionally helpful when using the Composite WPF guidance, but my current attempts to replace Unity with MEF have been unsuccessful as I can't find this feature in MEF.
Dec 19, 2008 at 10:27 PM
I'm not sure we intent to solve the same problems Unity tries to solve, nor we would have the same features. That said, you can add instances through the method AddPart exposed by the MutableExportProvider, but also available on the CompositionContainer.
Dec 19, 2008 at 10:47 PM

@riles01

Unity lets you build up an instance that has been explicitly added to the container. MEF does have this capability through the AddPart method that Hammett mentioned. After you add the part to the container, you need to call the Container.Compose method. The reason we don’t call it automatically is because you can add multiple parts before having them composed, for example you may have two parts that you are adding, and one depends on the other. When you call Compose, the parts that were manually added will have their imports satisfied.  

Note in a future drop Compose will actually accept a Composition Batch thus allowing you to pass in the parts and compose at the same time.

Glenn

From: riles01 [mailto:notifications@codeplex.com]
Sent: Friday, December 19, 2008 8:28 AM
To: Glenn Block
Subject: Registering Instances [MEF:42697]

From: riles01

Does MEF have a story for registering or caching instances once they're resolved? The ability to register instances makes Unity exceptionally helpful when using the Composite WPF guidance, but my current attempts to replace Unity with MEF have been unsuccessful as I can't find this feature in MEF.

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com