uploads/131/Test.zipHello
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