React to DI changes

This commit is contained in:
Hao Kung 2015-03-04 18:25:49 -08:00
parent c632c8a6a4
commit 7adf11b7bc
12 changed files with 14 additions and 27 deletions

View File

@ -13,33 +13,30 @@ namespace Microsoft.Framework.DependencyInjection
public static class HostingServicesExtensions public static class HostingServicesExtensions
{ {
// REVIEW: Logging doesn't depend on DI, where should this live? // REVIEW: Logging doesn't depend on DI, where should this live?
public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) public static IServiceCollection AddLogging(this IServiceCollection services)
{ {
var describe = new ServiceDescriber(config); services.TryAdd(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>());
services.TryAdd(describe.Singleton<ILoggerFactory, LoggerFactory>()); services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>)));
services.TryAdd(describe.Singleton(typeof(ILogger<>), typeof(Logger<>)));
return services; return services;
} }
public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null)
{ {
var describer = new ServiceDescriber(configuration); services.TryAdd(ServiceDescriptor.Transient<IHostingEngine, HostingEngine>());
services.TryAdd(ServiceDescriptor.Transient<IServerLoader, ServerLoader>());
services.TryAdd(describer.Transient<IHostingEngine, HostingEngine>()); services.TryAdd(ServiceDescriptor.Transient<IStartupLoader, StartupLoader>());
services.TryAdd(describer.Transient<IServerLoader, ServerLoader>());
services.TryAdd(describer.Transient<IStartupLoader, StartupLoader>()); services.TryAdd(ServiceDescriptor.Transient<IApplicationBuilderFactory, ApplicationBuilderFactory>());
services.TryAdd(ServiceDescriptor.Transient<IHttpContextFactory, HttpContextFactory>());
services.TryAdd(describer.Transient<IApplicationBuilderFactory, ApplicationBuilderFactory>()); services.TryAdd(ServiceDescriptor.Instance<IApplicationLifetime>(new ApplicationLifetime()));
services.TryAdd(describer.Transient<IHttpContextFactory, HttpContextFactory>());
services.TryAdd(describer.Instance<IApplicationLifetime>(new ApplicationLifetime()));
services.AddTypeActivator(configuration); services.AddTypeActivator(configuration);
// TODO: Do we expect this to be provide by the runtime eventually? // TODO: Do we expect this to be provide by the runtime eventually?
services.AddLogging(configuration); services.AddLogging();
services.TryAdd(describer.Singleton<IHostingEnvironment, HostingEnvironment>()); services.TryAdd(ServiceDescriptor.Singleton<IHostingEnvironment, HostingEnvironment>());
services.TryAdd(describer.Singleton<IHttpContextAccessor, HttpContextAccessor>()); services.TryAdd(ServiceDescriptor.Singleton<IHttpContextAccessor, HttpContextAccessor>());
// REVIEW: don't try add because we pull out IEnumerable<IConfigureHostingEnvironment>? // REVIEW: don't try add because we pull out IEnumerable<IConfigureHostingEnvironment>?
services.AddInstance<IConfigureHostingEnvironment>(new ConfigureHostingEnvironment(configuration)); services.AddInstance<IConfigureHostingEnvironment>(new ConfigureHostingEnvironment(configuration));

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
namespace Microsoft.AspNet.Hosting.Startup namespace Microsoft.AspNet.Hosting.Startup
{ {

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using Microsoft.AspNet.RequestContainer; using Microsoft.AspNet.RequestContainer;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Builder
// Note: Manifests are lost after UseServices, services are flattened into ApplicationServices // Note: Manifests are lost after UseServices, services are flattened into ApplicationServices
public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IEnumerable<IServiceDescriptor> applicationServices) public static IApplicationBuilder UseServices(this IApplicationBuilder builder, IServiceCollection applicationServices)
{ {
return builder.UseServices(services => services.Add(applicationServices)); return builder.UseServices(services => services.Add(applicationServices));
} }

View File

@ -11,7 +11,6 @@ using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Infrastructure; using Microsoft.Framework.Runtime.Infrastructure;

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using System; using System;

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Hosting namespace Microsoft.AspNet.Hosting

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Fakes;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Runtime; using Microsoft.Framework.Runtime;
using Xunit; using Xunit;

View File

@ -7,7 +7,6 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting.Fakes; using Microsoft.AspNet.Hosting.Fakes;
using Microsoft.AspNet.Hosting.Startup; using Microsoft.AspNet.Hosting.Startup;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Xunit; using Xunit;

View File

@ -6,7 +6,6 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http.Core; using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.RequestContainer; using Microsoft.AspNet.RequestContainer;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Xunit; using Xunit;

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.DependencyInjection;
using Xunit; using Xunit;
namespace Microsoft.AspNet.TestHost namespace Microsoft.AspNet.TestHost

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit; using Xunit;
namespace Microsoft.AspNet.TestHost namespace Microsoft.AspNet.TestHost