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-10-25 15:07:04 +02:00
|
|
|
|
using Umbraco.Core.Exceptions;
|
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
|
2018-11-28 11:05:41 +01:00
|
|
|
|
Module = Current.Factory.GetInstance<TModule>();
|
2018-09-02 22:09:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2018-10-25 15:07:04 +02:00
|
|
|
|
// if GetInstance fails, it may be because of a boot error, in
|
|
|
|
|
|
// which case that is the error we actually want to report
|
|
|
|
|
|
IRuntimeState runtimeState = null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2018-09-02 22:09:37 +02:00
|
|
|
|
{
|
2018-11-28 11:05:41 +01:00
|
|
|
|
runtimeState = Current.Factory.GetInstance<IRuntimeState>();
|
2018-09-02 22:09:37 +02:00
|
|
|
|
}
|
2018-10-25 15:07:04 +02:00
|
|
|
|
catch { /* don't make it worse */ }
|
|
|
|
|
|
|
|
|
|
|
|
if (runtimeState?.BootFailedException != null)
|
|
|
|
|
|
BootFailedException.Rethrow(runtimeState.BootFailedException);
|
|
|
|
|
|
|
|
|
|
|
|
// else... throw what we have
|
|
|
|
|
|
throw;
|
2018-09-02 22:09:37 +02:00
|
|
|
|
}
|
2018-10-25 15:07:04 +02:00
|
|
|
|
|
|
|
|
|
|
// initialize
|
|
|
|
|
|
Module.Init(context);
|
2018-07-06 18:37:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
Module?.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|