2018-09-02 22:09:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Web;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core;
|
2018-07-20 16:39:39 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
2018-07-06 18:37:07 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Composing
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Provides a base class for module injectors.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TModule">The type of the injected module.</typeparam>
|
|
|
|
|
|
public abstract class ModuleInjector<TModule> : IHttpModule
|
|
|
|
|
|
where TModule : IHttpModule
|
|
|
|
|
|
{
|
|
|
|
|
|
protected TModule Module { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public void Init(HttpApplication context)
|
|
|
|
|
|
{
|
2018-09-02 22:09:37 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// using the service locator here - no other way, really
|
|
|
|
|
|
Module = Current.Container.GetInstance<TModule>();
|
|
|
|
|
|
Module.Init(context);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
var runtimeState = Current.Container.GetInstance<IRuntimeState>();
|
|
|
|
|
|
if (runtimeState.BootFailedException != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("Failed to boot", runtimeState.BootFailedException);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-06 18:37:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
Module?.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|