Reacting to DependencyInjection changes

This commit is contained in:
Pranav K 2015-11-13 10:47:34 -08:00
parent b8b222b295
commit 292207d17d
44 changed files with 64 additions and 65 deletions

View File

@ -69,7 +69,7 @@ namespace Microsoft.Extensions.DependencyInjection
var initializer = new TagHelperInitializer<TTagHelper>(initialize);
builder.Services.AddInstance(typeof(ITagHelperInitializer<TTagHelper>), initializer);
builder.Services.AddSingleton(typeof(ITagHelperInitializer<TTagHelper>), initializer);
return builder;
}

View File

@ -110,7 +110,7 @@ namespace Microsoft.Extensions.DependencyInjection
var initializer = new TagHelperInitializer<TTagHelper>(initialize);
builder.Services.AddInstance(typeof(ITagHelperInitializer<TTagHelper>), initializer);
builder.Services.AddSingleton(typeof(ITagHelperInitializer<TTagHelper>), initializer);
return builder;
}

View File

@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}
}

View File

@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices(params ViewComponentDescriptor[] descriptors)
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -2145,7 +2145,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Mvc
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -109,7 +109,7 @@ namespace Microsoft.AspNet.Mvc
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -96,7 +96,7 @@ namespace Microsoft.AspNet.Mvc
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -107,7 +107,7 @@ namespace Microsoft.AspNet.Mvc
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -217,7 +217,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -156,7 +156,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -213,8 +213,7 @@ namespace Microsoft.AspNet.Mvc.Filters
.RequireClaim("Permission", "CanViewComment")
.Build());
var authorizationContext = GetAuthorizationContext(services =>
services.AddInstance(authorizationService.Object)
);
services.AddSingleton(authorizationService.Object));
authorizationContext.Result = new HttpUnauthorizedResult();

View File

@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceProvider CreateServices()
{
return new ServiceCollection()
.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance)
.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance)
.BuildServiceProvider();
}
}

View File

@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Mvc
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}
}

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -435,7 +435,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceProvider GetServiceProvider(IUrlHelper urlHelper)
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<IUrlHelper>(urlHelper);
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
return serviceCollection.BuildServiceProvider();
}

View File

@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var services = new ServiceCollection();
services.AddInstance<IService>(new Service());
services.AddSingleton<IService>(new Service());
var bindingContext = new ModelBindingContext
{

View File

@ -65,12 +65,12 @@ namespace Microsoft.AspNet.Mvc
private static IServiceProvider CreateServices()
{
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
new TestOptionsManager<MvcOptions>(),
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),
NullLoggerFactory.Instance));
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services.BuildServiceProvider();
}

View File

@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Mvc
// Assert
Assert.NotNull(httpContext.Response.Body);
var contents = await new StreamReader(httpContext.Response.Body).ReadToEndAsync();
Assert.Equal("FilePathResultTestFile contents¡", contents);
Assert.Equal("FilePathResultTestFile contents<EFBFBD>", contents);
}
[Fact]
@ -120,7 +120,7 @@ namespace Microsoft.AspNet.Mvc
// Assert
Assert.NotNull(httpContext.Response.Body);
var contents = await new StreamReader(httpContext.Response.Body).ReadToEndAsync();
Assert.Equal("FilePathResultTestFile contents¡", contents);
Assert.Equal("FilePathResultTestFile contents<EFBFBD>", contents);
}
[Theory]
@ -204,7 +204,7 @@ namespace Microsoft.AspNet.Mvc
}
else
{
return new MemoryStream(Encoding.UTF8.GetBytes("FilePathResultTestFile contents¡"));
return new MemoryStream(Encoding.UTF8.GetBytes("FilePathResultTestFile contents<EFBFBD>"));
}
}
}
@ -212,7 +212,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -110,7 +110,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceProvider GetServiceProvider(IUrlHelper urlHelper)
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<IUrlHelper>(urlHelper);
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
serviceCollection.AddTransient<ILoggerFactory, LoggerFactory>();
return serviceCollection.BuildServiceProvider();
}

View File

@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}
}

View File

@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc
private static IServiceCollection CreateServices()
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Mvc
var httpContext = GetHttpContext();
httpContext.Response.Body = new MemoryStream();
httpContext.RequestServices = new ServiceCollection()
.AddInstance<IHostingEnvironment>(appEnvironment.Object)
.AddSingleton<IHostingEnvironment>(appEnvironment.Object)
.AddTransient<ILoggerFactory, LoggerFactory>()
.BuildServiceProvider();
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
@ -294,7 +294,7 @@ namespace Microsoft.AspNet.Mvc
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.Cors
}
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
httpContext.RequestServices = services.BuildServiceProvider();
var method = isPreflight ? CorsConstants.PreflightHttpMethod : "GET";

View File

@ -173,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
var services = new ServiceCollection();
services.AddOptions();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
httpContext.RequestServices = services.BuildServiceProvider();
return httpContext;

View File

@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc
new TestOptionsManager<MvcJsonOptions>());
var services = new ServiceCollection();
services.AddInstance(executor);
services.AddSingleton(executor);
httpContext.RequestServices = services.BuildServiceProvider();
return httpContext;

View File

@ -106,17 +106,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
return (services) =>
{
services.AddInstance<IApplicationEnvironment>(
services.AddSingleton<IApplicationEnvironment>(
new TestApplicationEnvironment(applicationEnvironment, applicationName, applicationRoot));
var hostingEnvironment = new HostingEnvironment();
hostingEnvironment.Initialize(applicationRoot, new WebHostOptions());
services.AddInstance<IHostingEnvironment>(hostingEnvironment);
services.AddSingleton<IHostingEnvironment>(hostingEnvironment);
// Inject a custom assembly provider. Overrides AddMvc() because that uses TryAdd().
var assemblyProvider = new StaticAssemblyProvider();
assemblyProvider.CandidateAssemblies.Add(startupAssembly);
services.AddInstance<IAssemblyProvider>(assemblyProvider);
services.AddSingleton<IAssemblyProvider>(assemblyProvider);
AddAdditionalServices(services);

View File

@ -233,10 +233,10 @@ namespace Microsoft.AspNet.Mvc
private static void AddDnxServices(IServiceCollection serviceCollection)
{
serviceCollection.AddInstance(Mock.Of<ILibraryManager>());
serviceCollection.AddInstance(Mock.Of<ILibraryExporter>());
serviceCollection.AddInstance(Mock.Of<ICompilerOptionsProvider>());
serviceCollection.AddInstance(Mock.Of<IAssemblyLoadContextAccessor>());
serviceCollection.AddSingleton(Mock.Of<ILibraryManager>());
serviceCollection.AddSingleton(Mock.Of<ILibraryExporter>());
serviceCollection.AddSingleton(Mock.Of<ICompilerOptionsProvider>());
serviceCollection.AddSingleton(Mock.Of<IAssemblyLoadContextAccessor>());
var applicationEnvironment = new Mock<IApplicationEnvironment>();
// ApplicationBasePath is used to set up a PhysicalFileProvider which requires
@ -244,7 +244,7 @@ namespace Microsoft.AspNet.Mvc
applicationEnvironment.SetupGet(e => e.ApplicationBasePath)
.Returns(Directory.GetCurrentDirectory());
serviceCollection.AddInstance(applicationEnvironment.Object);
serviceCollection.AddSingleton(applicationEnvironment.Object);
}
}
}

View File

@ -119,7 +119,7 @@ namespace Microsoft.AspNet.Mvc
NullLoggerFactory.Instance);
var services = new ServiceCollection();
services.AddInstance(viewExecutor);
services.AddSingleton(viewExecutor);
var httpContext = new DefaultHttpContext();
httpContext.RequestServices = services.BuildServiceProvider();

View File

@ -443,7 +443,7 @@ namespace Microsoft.AspNet.Mvc
private static ClientModelValidationContext GetValidationContext(IUrlHelper urlHelper)
{
var serviceCollection = GetServiceCollection();
serviceCollection.AddInstance<IUrlHelper>(urlHelper);
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
var serviceProvider = serviceCollection.BuildServiceProvider();
return new ClientModelValidationContext(_metadata, _metadataProvider, serviceProvider);
@ -474,7 +474,7 @@ namespace Microsoft.AspNet.Mvc
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object);
serviceCollection.AddInstance<IUrlHelper>(urlHelper);
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
serviceProvider = serviceCollection.BuildServiceProvider();
return new ClientModelValidationContext(_metadata, _metadataProvider, serviceProvider);
@ -496,7 +496,7 @@ namespace Microsoft.AspNet.Mvc
var contextAccessor = GetContextAccessor(serviceProvider, routeData);
var actionSelector = new Mock<IActionSelector>(MockBehavior.Strict);
var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object);
serviceCollection.AddInstance<IUrlHelper>(urlHelper);
serviceCollection.AddSingleton<IUrlHelper>(urlHelper);
serviceProvider = serviceCollection.BuildServiceProvider();
return new ClientModelValidationContext(_metadata, _metadataProvider, serviceProvider);
@ -572,7 +572,7 @@ namespace Microsoft.AspNet.Mvc
private static ServiceCollection GetServiceCollection()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<ILoggerFactory>(new NullLoggerFactory());
serviceCollection.AddSingleton<ILoggerFactory>(new NullLoggerFactory());
var routeOptions = new RouteOptions();
var accessor = new Mock<IOptions<RouteOptions>>();
@ -580,9 +580,9 @@ namespace Microsoft.AspNet.Mvc
.SetupGet(options => options.Value)
.Returns(routeOptions);
serviceCollection.AddInstance<IOptions<RouteOptions>>(accessor.Object);
serviceCollection.AddSingleton<IOptions<RouteOptions>>(accessor.Object);
serviceCollection.AddInstance<IInlineConstraintResolver>(
serviceCollection.AddSingleton<IInlineConstraintResolver>(
new DefaultInlineConstraintResolver(accessor.Object));
return serviceCollection;

View File

@ -467,7 +467,7 @@ namespace Microsoft.AspNet.Mvc
}
var services = new ServiceCollection();
services.AddInstance<DiagnosticSource>(diagnosticSource);
services.AddSingleton<DiagnosticSource>(diagnosticSource);
services.AddSingleton<IOptions<MvcViewOptions>, TestOptionsManager<MvcViewOptions>>();
services.AddTransient<IViewComponentHelper, DefaultViewComponentHelper>();
services.AddSingleton<IViewComponentSelector, DefaultViewComponentSelector>();
@ -475,10 +475,10 @@ namespace Microsoft.AspNet.Mvc
services.AddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
services.AddSingleton<ITypeActivatorCache, DefaultTypeActivatorCache>();
services.AddSingleton<IViewComponentActivator, DefaultViewComponentActivator>();
services.AddInstance<IViewComponentDescriptorProvider>(new FixedSetViewComponentDescriptorProvider(descriptors));
services.AddSingleton<IViewComponentDescriptorProvider>(new FixedSetViewComponentDescriptorProvider(descriptors));
services.AddSingleton<IModelMetadataProvider, EmptyModelMetadataProvider>();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddInstance<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider));
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider));
services.AddTransient<IHttpContextAccessor, HttpContextAccessor>();
return services;

View File

@ -128,9 +128,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
var httpContext = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() };
var serviceCollection = new ServiceCollection();
serviceCollection.AddInstance<IModelMetadataProvider>(new EmptyModelMetadataProvider());
serviceCollection.AddSingleton<IModelMetadataProvider>(new EmptyModelMetadataProvider());
var tempDataProvider = new SessionStateTempDataProvider();
serviceCollection.AddInstance<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider));
serviceCollection.AddSingleton<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider));
return serviceCollection.BuildServiceProvider();
}

View File

@ -118,7 +118,7 @@ namespace Microsoft.AspNet.Mvc
NullLoggerFactory.Instance);
var services = new ServiceCollection();
services.AddInstance(viewExecutor);
services.AddSingleton(viewExecutor);
var httpContext = new DefaultHttpContext();
httpContext.RequestServices = services.BuildServiceProvider();

View File

@ -74,7 +74,7 @@ namespace System.Web.Http
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -34,7 +34,7 @@ namespace System.Web.Http
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -74,7 +74,7 @@ namespace System.Web.Http
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -34,7 +34,7 @@ namespace System.Web.Http
{
var services = new ServiceCollection();
services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
return services;
}

View File

@ -87,7 +87,7 @@ namespace System.Web.Http
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -74,7 +74,7 @@ namespace System.Web.Http
options.Value.OutputFormatters.Add(new JsonOutputFormatter());
var services = new ServiceCollection();
services.AddInstance(new ObjectResultExecutor(
services.AddSingleton(new ObjectResultExecutor(
options,
new ActionBindingContextAccessor(),
new TestHttpResponseStreamWriterFactory(),

View File

@ -16,7 +16,7 @@ namespace ActionResultsWebSite
.AddMvc()
.AddXmlDataContractSerializerFormatters();
services.AddInstance(new GuidLookupService());
services.AddSingleton(new GuidLookupService());
}
public void Configure(IApplicationBuilder app)

View File

@ -13,7 +13,7 @@ namespace ActivatorWebSite
{
// Add MVC services to the services container
services.AddMvc();
services.AddInstance(new MyService());
services.AddSingleton(new MyService());
services.AddScoped<ViewService, ViewService>();
}