diff --git a/src/Microsoft.AspNet.Hosting/HostingServices.cs b/src/Microsoft.AspNet.Hosting/HostingServices.cs index 9032db6706..3f9555448e 100644 --- a/src/Microsoft.AspNet.Hosting/HostingServices.cs +++ b/src/Microsoft.AspNet.Hosting/HostingServices.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Hosting.Builder; @@ -18,69 +17,24 @@ namespace Microsoft.AspNet.Hosting public static IEnumerable GetDefaultServices(IConfiguration configuration) { - yield return DescribeService(configuration); - yield return DescribeService(configuration); + var describer = new ServiceDescriber(configuration); - yield return DescribeService(configuration); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); - yield return DescribeService(configuration); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); - yield return DescribeService(configuration); + yield return describer.Transient(); + yield return describer.Transient(); + + yield return describer.Transient(); // The default IDataProtectionProvider is a singleton. // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to // replace this service as part of application initialization. - yield return new ServiceDescriptor { - ServiceType = typeof(IDataProtectionProvider), - Lifecycle = LifecycleKind.Singleton, - ImplementationInstance = DataProtectionProvider.CreateFromDpapi() - }; - } - - public static IServiceDescriptor DescribeService(IConfiguration configuration, - LifecycleKind lifecycle = LifecycleKind.Transient) - { - return DescribeService(typeof(TService), typeof(TImplementation), configuration, lifecycle); - } - - public static IServiceDescriptor DescribeService( - Type serviceType, - Type implementationType, - IConfiguration configuration, - LifecycleKind lifecycle) - { - var serviceTypeName = serviceType.FullName; - var implementationTypeName = configuration.Get(serviceTypeName); - if (!String.IsNullOrEmpty(implementationTypeName)) - { - try - { - implementationType = Type.GetType(implementationTypeName); - } - catch (Exception ex) - { - throw new Exception(string.Format("TODO: unable to locate implementation {0} for service {1}", implementationTypeName, serviceTypeName), ex); - } - } - return new ServiceTypeDescriptor(serviceType, implementationType, lifecycle); - } - - public class ServiceTypeDescriptor : IServiceDescriptor - { - public ServiceTypeDescriptor(Type serviceType, Type implementationType, LifecycleKind lifecycle) - { - ServiceType = serviceType; - ImplementationType = implementationType; - Lifecycle = lifecycle; - } - - public LifecycleKind Lifecycle { get; private set; } - public Type ServiceType { get; private set; } - public Type ImplementationType { get; private set; } - public object ImplementationInstance { get; private set; } + yield return describer.Instance(DataProtectionProvider.CreateFromDpapi()); } } } \ No newline at end of file