Taylohtio/GeneralApi/GeneralApi.Core/Infrastructure/Web/DependencyRegistarModule.cs

41 lines
1.1 KiB
C#

using System;
using System.Web;
using GeneralApi.Core.Infrastructure.IoC;
namespace Taloyhtio.GeneralApi.Core.Infrastructure.Web
{
public class DependencyRegistrarModule : IHttpModule
{
private static bool dependenciesRegistered;
private static readonly object lockObject = new object();
public void Init(HttpApplication context)
{
context.BeginRequest += context_BeginRequest;
}
public void Dispose() { }
private static void context_BeginRequest(object sender, EventArgs e)
{
ensureDependenciesRegistered();
}
private static void ensureDependenciesRegistered()
{
// configuration is required only once per AppDomain
if (!dependenciesRegistered)
{
lock (lockObject)
{
if (!dependenciesRegistered)
{
IoCConfiguration.Configure();
dependenciesRegistered = true;
}
}
}
}
}
}