Move registration of nested provider infrastructure

The DI system has support for registering open generics now, so we can go
through that instead of directly through autofac.
This commit is contained in:
Ryan Nowak 2014-03-21 13:59:35 -07:00
parent 5b6eb307ae
commit dc6843acf7
3 changed files with 23 additions and 18 deletions

View File

@ -1,10 +1,8 @@
#if NET45 
using System; #if NET45
using Autofac;
using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Autofac; using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
@ -14,17 +12,11 @@ namespace MvcSample.Web
{ {
public void Configuration(IBuilder builder) public void Configuration(IBuilder builder)
{ {
var containerBuilder = new ContainerBuilder(); var services = new ServiceCollection();
var services = MvcServices.GetDefaultServices(); services.Add(MvcServices.GetDefaultServices());
services.AddSingleton<PassThroughAttribute, PassThroughAttribute>();
AutofacRegistration.Populate(containerBuilder, builder.ServiceProvider, services); var serviceProvider = services.BuildServiceProvider(builder.ServiceProvider);
containerBuilder.RegisterInstance<PassThroughAttribute>(new PassThroughAttribute());
// Temporary until we have support for open generics in our DI system.
containerBuilder.RegisterGeneric(typeof(NestedProviderManager<>)).As(typeof(INestedProviderManager<>));
containerBuilder.RegisterGeneric(typeof(NestedProviderManagerAsync<>)).As(typeof(INestedProviderManagerAsync<>));
var serviceProvider = containerBuilder.Build().Resolve<IServiceProvider>();
var routes = new RouteCollection() var routes = new RouteCollection()
{ {

View File

@ -16,9 +16,7 @@
"configurations": { "configurations": {
"net45": { "net45": {
"dependencies": { "dependencies": {
"Autofac": "3.3.0", "System.ComponentModel.DataAnnotations": ""
"System.ComponentModel.DataAnnotations": "",
"Microsoft.AspNet.DependencyInjection.Autofac": "0.1-alpha-*"
} }
}, },
"k10": { "k10": {

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.ConfigurationModel; using Microsoft.AspNet.ConfigurationModel;
using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.NestedProviders;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
@ -66,6 +67,20 @@ namespace Microsoft.AspNet.Mvc
yield return describe.Transient<IModelValidatorProvider, DataAnnotationsModelValidatorProvider>(); yield return describe.Transient<IModelValidatorProvider, DataAnnotationsModelValidatorProvider>();
yield return describe.Transient<IModelValidatorProvider, DataMemberModelValidatorProvider>(); yield return describe.Transient<IModelValidatorProvider, DataMemberModelValidatorProvider>();
yield return
describe.Describe(
typeof(INestedProviderManager<>),
typeof(NestedProviderManager<>),
implementationInstance: null,
lifecycle: LifecycleKind.Transient);
yield return
describe.Describe(
typeof(INestedProviderManagerAsync<>),
typeof(NestedProviderManagerAsync<>),
implementationInstance: null,
lifecycle: LifecycleKind.Transient);
} }
} }
} }