Skip to content

Commit 46799d0

Browse files
committed
Remove and dispose existing plugin when adding a new one.
1 parent f461a43 commit 46799d0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Exceptionless.Portable/Configuration/ExceptionlessConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public IEnumerable<PluginRegistration> Plugins {
297297
/// <param name="plugin">The plugin instance to be added.</param>
298298
public void AddPlugin<T>(T plugin) where T : IEventPlugin {
299299
string key = typeof(T).FullName;
300+
RemovePlugin(key);
300301
_plugins[key] = new PluginRegistration(key, GetPriority(typeof(T)), new Lazy<IEventPlugin>(() => plugin));
301302
}
302303

@@ -314,6 +315,7 @@ public void AddPlugin<T>() where T : IEventPlugin {
314315
/// <param name="key">The key used to identify the plugin.</param>
315316
/// <param name="pluginType">The plugin type to be added.</param>
316317
public void AddPlugin(string key, Type pluginType) {
318+
RemovePlugin(key);
317319
_plugins[key] = new PluginRegistration(key, GetPriority(pluginType), new Lazy<IEventPlugin>(() => Resolver.Resolve(pluginType) as IEventPlugin));
318320
}
319321

@@ -333,6 +335,7 @@ public void AddPlugin(string key, Func<ExceptionlessConfiguration, IEventPlugin>
333335
/// <param name="priority">Used to determine plugins priority.</param>
334336
/// <param name="factory">A factory method to create the plugin.</param>
335337
public void AddPlugin(string key, int priority, Func<ExceptionlessConfiguration, IEventPlugin> factory) {
338+
RemovePlugin(key);
336339
_plugins[key] = new PluginRegistration(key, priority, new Lazy<IEventPlugin>(() => factory(this)));
337340
}
338341

@@ -360,6 +363,7 @@ public void AddPlugin(string key, Action<EventPluginContext> pluginAction) {
360363
/// <param name="priority">Used to determine plugins priority.</param>
361364
/// <param name="pluginAction">The plugin action to run.</param>
362365
public void AddPlugin(string key, int priority, Action<EventPluginContext> pluginAction) {
366+
RemovePlugin(key);
363367
_plugins[key] = new PluginRegistration(key, priority, new Lazy<IEventPlugin>(() => new ActionPlugin(pluginAction)));
364368
}
365369

0 commit comments

Comments
 (0)