I trying to implement a global cache repository as TempHire does. So, when registering an event with weak reference I receive an error:
Error Message:
Exception has been thrown by the target of an invocation.
Detail:
Attempt by method 'IdeaBlade.Core.WeakEventHandler`2<System.__Canon,System.__Canon>..ctor(System.EventHandler`1<System.__Canon>, IdeaBlade.Core.UnregisterCallback`1<System.__Canon>)' to access method 'DomainServices.Helpers.GlobalCacheRepository`1<System.__Canon>.OnManagerCreated(System.Object, IdeaBlade.EntityModel.EntityManagerCreatedEventArgs)' failed.
Code:
public GlobalCacheRepository(IEntityManagerProvider entityManagerProvider, IGlobalCache globalCache)
: base(entityManagerProvider)
{
_globalCache = globalCache;
entityManagerProvider.ManagerCreated += new EventHandler<EntityManagerCreatedEventArgs>(OnManagerCreated)
.MakeWeak(eh => entityManagerProvider.ManagerCreated -= eh);
if (globalCache != null)
DefaultQueryStrategy = QueryStrategy.CacheOnly;
}
What am I doing wrong?
PS: If I don't use MakeWeak it works.