Well-Known Boundaries

Nov 3, 2013 at 11:27 AM
Edited Nov 3, 2013 at 11:30 AM
What's the deal with Microsoft.Composition.Demos.Web.Mvc.Boundaries?

It says it defines [w]ell-known sharing boundary names. The composition provider uses all of these when handling a web request and then goes on to define three:
// The boundary within which a
// current HTTP request is accessible.
public const string HttpRequest = "HttpRequest";

// The boundary within which a
// consistent view of persistent data is available.
public const string DataConsistency = "DataConsistency";

// The boundary within which a
// single user can be identified.
public const string UserIdentity = "UserIdentity";
As far as I can tell, these aren't "well-known" to anything, and at the end of the day they're all per-request care of CompositionProvider.CurrentInitialisedScope leaning on HttpContext.Current.

Which is to say, they might as well be called PerRequestBoundary1, PerRequestBoundary2, and PerRequestBoundary3.

Boundaries.cs hints at as much with: The composition provider uses all of these when handling a web request.

But basically it looks like everything but HttpRequest are misnomers: there's nothing about the string "UserIdentity" that actually links a part's lifetime to the request's user identity.
Nov 3, 2013 at 11:41 AM
I agree with you.
The string themselves are not important, what is important is the creation and destroy of CompositionContext.
You can see the code for library called alt-composition written by nblumhardt who was on the MEF team.
Specifically I suggest to look at MvcCompositionProvider.cs Line 34 where he creates a CompositionContract with the specified boundaries. As far as I can tell all those boundaries are exactly the same (as you said).

At line 65 you can see how he try to get exist composition context or creates new one and store it.

I am using this library and it works great but I think Google Guice Scopes are much clearer. I look at Guice because I find a lot of similarities between MEF and Guice and the both accomplish similar goals.

Ido
Nov 3, 2013 at 11:47 AM
ido_ran wrote:
You can see the code for library called alt-composition written by nblumhardt who was on the MEF team.
Thanks for the reference, I'll check out the source.