By placing the MEF composition code directly in the App.xaml.cs file SoapBox limits the accessibility of the composition container to that single class. As soon as the code exits the OnStartup method there is no way to access the composition container until the application shuts down, right? So why isn't the composition container disposed as soon as composition is complete? What's the use of the composition container after composition?

asked 01 Nov '11, 23:03

KarlB's gravatar image

accept rate: 0%

edited 01 Nov '11, 23:27

Scott%20Whitlock's gravatar image

Scott Whitlock ♦♦

Currently, SoapBox uses the composition container exclusively for application composition on start-up and does not provide a mechanism for accessing the composition container after start-up. You are absolutely right that the composition container could be disposed of as soon as composition is complete -- in-fact, you can try it yourself and you'll see that more eagerly disposing the composition catalog in the OnStartup method will not cause any problems, so long as you do it AFTER composition is complete! (No, really, try it. It requires you to change 2 lines of code and it is a good way to show/remind yourself that after composition an application that uses MEF is in no way different from an application that doesn't use MEF at all.)

Though you certainly could dispose of the composition container once composition completes, I prefer - and would suggest - doing the opposite. Namely, keep the composition container throughout the entire application lifecycle and make it more accessible to the add-ins. One approach to doing exactly this is detailed here: What To Do With MEF Composition Container After Application Start-Up. This post explains some of the added benefits had by the add-ins when the composition code is housed in its own class that exposes limited access of the composition container to interested add-ins.

I have no idea when the next release of SoapBoxCore will be, but I know I would love to see something like the CompositionService and the CompositionServiceLocator included in it for exactly the type of situation described in the referenced blog post.


answered 01 Nov '11, 23:06

KarlB's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 01 Nov '11, 23:03

Seen: 1,985 times

Last updated: 01 Nov '11, 23:27

powered by OSQA