New Posts New Posts RSS Feed: MEF and GlobalCache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

MEF and GlobalCache

 Post Reply Post Reply
Author
-ook View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Aug-2007
Location: Australia
Posts: 41
Post Options Post Options   Quote -ook Quote  Post ReplyReply Direct Link To This Post Topic: MEF and GlobalCache
    Posted: 03-Sep-2012 at 5:38am
uploads/131/Test.zip

Hello

I am having an issue with the MEF instantiation of the IGlobalCache class (from TempHire) when defined as a parameter to a ViewModel constructor. To illustrate I have created a very simple test application (attached). It contains one viewmodel (no associated view as it is unimportant at this stage), the IGlobalCache interface and derived class GlobalCache and a Entity model obtained by a few tables from the Adventureworks 2008 R2 sample database from Microsoft.

The ViewModel in question (MyTestViewModel) has a constructor of:

[ImportingConstructor]

public MyTestViewModel(IGlobalCache oface){}

And the Bootstrapper is set to launch MyTestViewModel. However, when the application runs I get the error message "Could not locate any instances of contract Test.ViewModels.MyTestViewModel.".

 

I note that when I change the constructor of the GlobalCache class from this:

// this does not work

[ImportingConstructor]

public GlobalCache([Import(RequiredCreationPolicy = CreationPolicy.NonShared)] IEntityManagerProvider<AdventureWorks2008R2Entities> entityManagerProvider)

{

_entityManagerProvider = entityManagerProvider;

}

 

To this:

[ImportingConstructor]

public GlobalCache()

{

 

}

 

Then the error goes away and the application runs, however the entityManagerProvider is obviously not set and hence the GlobalCache is of somewhat limited use.

Any ideas what I am not doing correctly?

Thanks

Mark

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: 03-Sep-2012 at 9:31pm
Where's your export for  IEntityManagerProvider<AdventureWorks2008R2Entities>? See the EntityManagerProviderFactory in TempHire.
Back to Top
-ook View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Aug-2007
Location: Australia
Posts: 41
Post Options Post Options   Quote -ook Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2012 at 9:57pm
Of course, such a silly oversight. Sorry, I am quite new to MEF and all these levels of abstraction  are difficult to follow - it is all smoke and mirrors to me at the moment.
 
Thankyou for the quick reply.
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down