Files
Umbraco-CMS/src/Umbraco.Web/HealthCheck/HealthCheckResolver.cs
Gunnar Már Óttarsson 053175a5a6 Fix http://issues.umbraco.org/issue/U4-9562
Change HealthCheckResolver to public allowing DI
2017-09-13 19:24:46 +00:00

56 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Web;
using Umbraco.Core.Logging;
using Umbraco.Core.ObjectResolution;
namespace Umbraco.Web.HealthCheck
{
/// <summary>
/// Resolves all health check instances
/// </summary>
/// <remarks>
/// Each instance scoped to the lifespan of the http request
/// </remarks>
public class HealthCheckResolver : LazyManyObjectsResolverBase<HealthCheckResolver, HealthCheck>, IHealthCheckResolver
{
public HealthCheckResolver(ILogger logger, Func<IEnumerable<Type>> lazyTypeList)
: base(new HealthCheckServiceProvider(), logger, lazyTypeList, ObjectLifetimeScope.HttpRequest)
{
}
/// <summary>
/// Returns all health check instances
/// </summary>
public IEnumerable<HealthCheck> HealthChecks
{
get { return Values; }
}
/// <summary>
/// This will ctor the HealthCheck instances
/// </summary>
/// <remarks>
/// This is like a super crappy DI - in v8 we have real DI
/// </remarks>
private class HealthCheckServiceProvider : IServiceProvider
{
public object GetService(Type serviceType)
{
var normalArgs = new[] { typeof(HealthCheckContext) };
var found = serviceType.GetConstructor(normalArgs);
if (found != null)
{
return found.Invoke(new object[]
{
new HealthCheckContext(new HttpContextWrapper(HttpContext.Current), UmbracoContext.Current)
});
}
//use normal ctor
return Activator.CreateInstance(serviceType);
}
}
}
}