Hi guys,
I've written a structure of global cache exactly like TempHire does.
So, in the constructor of my GlobalCacheRepository:
entityManagerProvider.ManagerCreated += new EventHandler<EntityManagerCreatedEventArgs>(OnManagerCreated)
.MakeWeak(eh => entityManagerProvider.ManagerCreated -= eh);
And:
internal void OnManagerCreated(object sender, EntityManagerCreatedEventArgs e)
{
if (_globalCache == null) return;
Seed(e.EntityManager);
e.EntityManager.Cleared += new EventHandler<EntityManagerClearedEventArgs>(OnCleared)
.MakeWeak(eh => e.EntityManager.Cleared -= eh);
}
internal void OnCleared(object sender, EntityManagerClearedEventArgs e)
{
Seed(e.EntityManager);
}
private void Seed(EntityManager entityManager)
{
var entities = _globalCache.Get<T>();
entityManager.ImportEntities(entities, MergeStrategy.OverwriteChanges);
}
But, when I run the app I realize that the method OnManagerCreated is never fired. Consequently, the ViewModel loads no results in my objects that read my global cache entities.
The method LoadAsync() in GlobalCache contains the cached entities that I need.
So, if I implement IDiscoverableViewModel in the same ViewModel and run the app through Harness, the global cache starts to work.
I think my mistake is something related to MEF.