Added context-sensitive init/dispose methods for plugins

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-09-06 10:18:54 -04:00
parent 908695d88a
commit 507beb76f6
3 changed files with 43 additions and 7 deletions

View File

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

View File

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

View File

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