Added context-sensitive init/dispose methods for plugins

pull/702/head
LukePulverenti Luke Pulverenti luke pulverenti 12 years ago
parent 908695d88a
commit 507beb76f6

@ -18,7 +18,7 @@ namespace MediaBrowser.Api
get { return "Media Browser API"; } get { return "Media Browser API"; }
} }
protected override void InitializeInternal() protected override void InitializeOnServer()
{ {
var httpServer = Kernel.Instance.HttpServer; var httpServer = Kernel.Instance.HttpServer;

@ -184,22 +184,58 @@ namespace MediaBrowser.Common.Plugins
if (Enabled) if (Enabled)
{ {
InitializeInternal(); if (kernel.KernelContext == KernelContext.Server)
{
InitializeOnServer();
}
else if (kernel.KernelContext == KernelContext.UI)
{
InitializeInUI();
}
} }
} }
} }
/// <summary> /// <summary>
/// Starts the plugin. /// Starts the plugin on the server
/// </summary>
protected virtual void InitializeOnServer()
{
}
/// <summary>
/// Starts the plugin in the UI
/// </summary> /// </summary>
protected virtual void InitializeInternal() protected virtual void InitializeInUI()
{ {
} }
/// <summary> /// <summary>
/// Disposes the plugins. Undos all actions performed during Init. /// Disposes the plugins. Undos all actions performed during Init.
/// </summary> /// </summary>
public virtual void Dispose() public void Dispose()
{
if (Context == KernelContext.Server)
{
DisposeOnServer();
}
else if (Context == KernelContext.UI)
{
InitializeInUI();
}
}
/// <summary>
/// Disposes the plugin on the server
/// </summary>
protected virtual void DisposeOnServer()
{
}
/// <summary>
/// Disposes the plugin in the UI
/// </summary>
protected virtual void DisposeInUI()
{ {
} }

@ -16,12 +16,12 @@ namespace MediaBrowser.TV
get { return "TV"; } get { return "TV"; }
} }
protected override void InitializeInternal() protected override void InitializeOnServer()
{ {
Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
} }
public override void Dispose() protected override void DisposeOnServer()
{ {
Kernel.Instance.ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath; Kernel.Instance.ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath;
} }

Loading…
Cancel
Save