New Posts New Posts RSS Feed: Composition issue on Shared instance
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Composition issue on Shared instance

 Post Reply Post Reply Page  <12
Author
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Topic: Composition issue on Shared instance
    Posted: 13-Sep-2012 at 12:49am
Here you go: http://sdrv.ms/QVuo6S
When you start it you should get "Service not available" and two buttons. Click the "Load Service" button. This loads the second XAP which contains the Service and you should see the service creation date/time above the button. Wait a few seconds and then click "Load Content". That loads the third assembly which contains a ViewModel that gets composed into the first ViewModel and that also gets the Service injected and then displays the service creation date/time in the View. You should see the exact same date/time now in both places indicating that the second VM got the same service injected as the first VM.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 13-Sep-2012 at 12:17am
I have only one bootstrapper in the application.
I checked if the Harness assembly was by mistake referenced by some modules and it isn't.

Would you mind sharing your test project so I can see what is different with my application (maybe I wasn't clear in my description) and I could modify it to try to reproduce the issue ?

Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2012 at 10:45pm
Neither. I believe this is a problem in your application. I recreated the scenario you are describing here and I can't reproduce this issue. The only thing that would explain this that I can think of is if your dynamically loaded XAPs instantiate additional bootstrappers. The bootstrapper creates the MEF container, so if you have more than one bootstrapper, each one creates a new container. You should have only one bootstrapper, otherwise bad things will happen if each XAP attempts to bootstrap the appliction all over again.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2012 at 3:58pm
Hi,

I have an issue with a service exported as Shared :

[Export(typeof(IContextRequirementSelection))]
[ExportMetadata("ContextName""Company")]
[PartCreationPolicy(CreationPolicy.Shared)]

This service is located  in a XAP which is dynamically loaded once the user login.


In the main application, I have a usercontrol which has an import on all the service implementing IContextRequirementSelection

[ImportMany(AllowRecomposition = true)] 
public IEnumerable<Lazy<IContextRequirementSelectionIContextRequirementMetadata>> ContextSelections;
Once the user login, the collection gets populated and when I access to the element with the metadata "Company", the instance is created.
Now, an action in my application load another XAP which also need to use this shared service.
I use the same syntaxe as the one above and MEF gives me a NEW instance of the service with the metadata "Company"

After reading a little bit on this subject, the only possibility seems to be if a new MEF container is created by the application.  
To try to confirm it, I changed for the test purpose the references in my application to add a reference to the assembly hosting the exported service.
Then, when I run the application, both usercontrols share the same instance as expected !

Is this a problem in cocktail or devforce ?

regards,


Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down