Created
July 15, 2010 07:29
-
-
Save glennblock/476626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//child catalog is a filtered catalog that contains only parts that should appear in the child (including TPart) | |
private TPart ComposePartWith<TPart>(ComposablePartCatalog childCatalog, CompositionContainer parentContainer, out IDisposable disposable, params object[] imports) | |
{ | |
var childContainer = new CompositionContainer(childCatalog, parentContainer); | |
childContainer.ComposeParts(imports); | |
disposable = childContainer; | |
return childContainer.GetExportedValue<TPart>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This method creates a child container and populates it with a set of exported instances. It uses a child catalog to set the parts that are in the child container. Finally it retrieves TPart from the child container which should result in the imports that were explicitly passed in being injected. The newly created container is returned as an out param in order to allow it to be disposed. You shoudl always dispoe of child containers to ensure all resources are reclaimed.