using System; using System.Collections.Generic; using System.Web; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; namespace Umbraco.Web.HealthCheck { /// /// Resolves all health check instances /// /// /// Each instance scoped to the lifespan of the http request /// public class HealthCheckResolver : LazyManyObjectsResolverBase, IHealthCheckResolver { public HealthCheckResolver(ILogger logger, Func> lazyTypeList) : base(new HealthCheckServiceProvider(), logger, lazyTypeList, ObjectLifetimeScope.HttpRequest) { } /// /// Returns all health check instances /// public IEnumerable HealthChecks { get { return Values; } } /// /// This will ctor the HealthCheck instances /// /// /// This is like a super crappy DI - in v8 we have real DI /// 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); } } } }