You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use MediatR to implement a plugin infrastructure for a table data program.
We defined messages in a plugin interface assembly which is used for each plugin. The plugin can also define their own messages.
Then we load the plugins via AssemblyLoadContext and register all request handlers vi DI and RegisterServicesFromAssembly().
Afterwards we can call the request handlers in the plugins via the IMediatR interface.
The issue is when we want unload the plugin during runtime.
We observed when we used "mediator.Publish" then there will be NotificationHandlerWrapper instances cached in a static field inside MediatR.
The wrappers are created here
and cached here.
The caching of these wrappers when they contain message types from the plugin assemblies prevents them from being unloaded properly.
We used the Visual Studio Memory to verify this:
We did not find a way to clear this cache except using reflection code:
// remove static references from Mediator when used "mediator.Publish"
var fieldInfo = typeof(MediatR.Mediator).GetField("_notificationHandlers", BindingFlags.Static | BindingFlags.NonPublic);
var value = (ConcurrentDictionary<Type, NotificationHandlerWrapper>)fieldInfo.GetValue(null);
value.Clear();
Is it possible to provide an official method to clear cached values inside MediatR?
The text was updated successfully, but these errors were encountered:
We use MediatR to implement a plugin infrastructure for a table data program.
We defined messages in a plugin interface assembly which is used for each plugin. The plugin can also define their own messages.
Then we load the plugins via AssemblyLoadContext and register all request handlers vi DI and RegisterServicesFromAssembly().
Afterwards we can call the request handlers in the plugins via the IMediatR interface.
The issue is when we want unload the plugin during runtime.
We observed when we used "mediator.Publish" then there will be NotificationHandlerWrapper instances cached in a static field inside MediatR.
The wrappers are created here
and cached here.
The caching of these wrappers when they contain message types from the plugin assemblies prevents them from being unloaded properly.
We used the Visual Studio Memory to verify this:
We did not find a way to clear this cache except using reflection code:
Is it possible to provide an official method to clear cached values inside MediatR?
The text was updated successfully, but these errors were encountered: