React to DI

This commit is contained in:
Hao Kung 2015-03-04 19:26:54 -08:00
parent b581ff343c
commit c290e897b0
25 changed files with 21 additions and 43 deletions

View File

@ -130,9 +130,9 @@ namespace Microsoft.Framework.DependencyInjection
private static void ConfigureDefaultServices(IServiceCollection services, IConfiguration configuration)
{
services.AddOptions(configuration);
services.AddDataProtection(configuration);
services.AddRouting(configuration);
services.AddOptions();
services.AddDataProtection();
services.AddRouting();
services.AddAuthorization(configuration);
services.AddWebEncoders();
services.Configure<RouteOptions>(routeOptions =>
@ -141,4 +141,4 @@ namespace Microsoft.Framework.DependencyInjection
typeof(KnownRouteValueConstraint)));
}
}
}
}

View File

@ -25,12 +25,12 @@ namespace Microsoft.AspNet.Mvc
{
public class MvcServices
{
public static IEnumerable<IServiceDescriptor> GetDefaultServices()
public static IEnumerable<ServiceDescriptor> GetDefaultServices()
{
return GetDefaultServices(null);
}
public static IEnumerable<IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
public static IEnumerable<ServiceDescriptor> GetDefaultServices(IConfiguration configuration)
{
var describe = new ServiceDescriber(configuration);
@ -172,4 +172,4 @@ namespace Microsoft.AspNet.Mvc
yield return describe.Transient<IApiDescriptionProvider, DefaultApiDescriptionProvider>();
}
}
}
}

View File

@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Framework.Cache.Memory;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Runtime.Roslyn;
@ -63,7 +62,7 @@ namespace Microsoft.AspNet.Mvc
// TODO: KILL THIS
private static IServiceProvider BuildFallbackServiceProvider(
IEnumerable<IServiceDescriptor> services,
IServiceCollection services,
IServiceProvider fallback)
{
var sc = HostingServices.Create(fallback);

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Http.Interfaces;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit;

View File

@ -13,7 +13,6 @@ using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
using Moq;

View File

@ -5,7 +5,6 @@ using System;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -3,7 +3,6 @@
using Microsoft.AspNet.DataProtection;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.OptionsModel;
using Microsoft.Framework.WebEncoders;
using Moq;

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.WebUtilities;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
using Moq;

View File

@ -9,7 +9,6 @@ using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Moq;
using Xunit;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.DependencyInjection.ServiceLookup;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
@ -117,7 +116,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
}
// TODO: Kill this code
private static IServiceProvider BuildFallbackServiceProvider(IEnumerable<IServiceDescriptor> services, IServiceProvider fallback)
private static IServiceProvider BuildFallbackServiceProvider(IEnumerable<ServiceDescriptor> services, IServiceProvider fallback)
{
var sc = HostingServices.Create(fallback);
sc.Add(services);

View File

@ -9,7 +9,6 @@ using Microsoft.AspNet.Http.Core;
using Moq;
using Xunit;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

@ -8,7 +8,6 @@ using System.ComponentModel.DataAnnotations;
using System.Linq;
#endif
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
#if ASPNET50
using Moq;
using Moq.Protected;

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Xunit;
namespace Microsoft.AspNet.Mvc.ModelBinding

View File

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

View File

@ -30,20 +30,20 @@ namespace Microsoft.AspNet.Mvc
Assert.Equal(4, services.Count);
Assert.Equal(typeof(ControllerTypeA), services[0].ServiceType);
Assert.Equal(typeof(ControllerTypeA), services[0].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[0].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[0].Lifetime);
Assert.Equal(typeof(TypeBController), services[1].ServiceType);
Assert.Equal(typeof(TypeBController), services[1].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[1].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
Assert.Equal(typeof(IControllerActivator), services[2].ServiceType);
Assert.Equal(typeof(ServiceBasedControllerActivator), services[2].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[2].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime);
Assert.Equal(typeof(IControllerTypeProvider), services[3].ServiceType);
var typeProvider = Assert.IsType<FixedSetControllerTypeProvider>(services[3].ImplementationInstance);
Assert.Equal(controllerTypes, typeProvider.ControllerTypes.OrderBy(c => c.Name));
Assert.Equal(LifecycleKind.Singleton, services[3].Lifecycle);
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
}
[Fact]
@ -69,19 +69,19 @@ namespace Microsoft.AspNet.Mvc
Assert.Equal(4, services.Count);
Assert.Equal(typeof(ControllerTypeA), services[0].ServiceType);
Assert.Equal(typeof(ControllerTypeA), services[0].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[0].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[0].Lifetime);
Assert.Equal(typeof(TypeBController), services[1].ServiceType);
Assert.Equal(typeof(TypeBController), services[1].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[1].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
Assert.Equal(typeof(IControllerActivator), services[2].ServiceType);
Assert.Equal(typeof(CustomActivator), services[2].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[2].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime);
Assert.Equal(typeof(IControllerTypeProvider), services[3].ServiceType);
Assert.Equal(typeof(CustomTypeProvider), services[3].ImplementationType);
Assert.Equal(LifecycleKind.Singleton, services[3].Lifecycle);
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
}
[Fact]
@ -102,21 +102,21 @@ namespace Microsoft.AspNet.Mvc
Assert.Equal(4, services.Count);
Assert.Equal(typeof(ControllerTypeA), services[0].ServiceType);
Assert.Equal(typeof(ControllerTypeA), services[0].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[0].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[0].Lifetime);
Assert.Equal(typeof(TypeBController), services[1].ServiceType);
Assert.Equal(typeof(TypeBController), services[1].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[1].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
Assert.Equal(typeof(IControllerActivator), services[2].ServiceType);
Assert.Equal(typeof(ServiceBasedControllerActivator), services[2].ImplementationType);
Assert.Equal(LifecycleKind.Transient, services[2].Lifecycle);
Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime);
Assert.Equal(typeof(IControllerTypeProvider), services[3].ServiceType);
var typeProvider = Assert.IsType<FixedSetControllerTypeProvider>(services[3].ImplementationInstance);
Assert.Equal(controllerTypes, typeProvider.ControllerTypes.OrderBy(c => c.Name));
Assert.Equal(LifecycleKind.Singleton, services[3].Lifecycle);
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
}
private class CustomActivator : IControllerActivator

View File

@ -7,7 +7,6 @@ using System.Runtime.Versioning;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Runtime;
namespace PrecompilationWebSite