Switching to the official Autofac package.

This commit is contained in:
Pranav K 2015-07-27 17:21:30 -07:00
parent 0ef68eefc8
commit 43e4870fa2
8 changed files with 100 additions and 123 deletions

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Autofac.Core; using Autofac.Core;
@ -108,4 +108,3 @@ namespace MvcSample.Web
} }
} }
} }
#endif

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Autofac; using Autofac;
@ -77,4 +76,3 @@ namespace MvcSample.Web
} }
} }
} }
#endif

View File

@ -2,22 +2,15 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
#if DNX451
using System.IO; using System.IO;
using Autofac; using Autofac;
#endif using Autofac.Framework.DependencyInjection;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Razor;
#if DNX451
using Microsoft.Framework.Configuration; using Microsoft.Framework.Configuration;
#endif
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
#if DNX451
using Microsoft.Framework.DependencyInjection.Autofac;
using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime;
using Microsoft.Dnx.Runtime.Infrastructure;
#endif
using MvcSample.Web.Filters; using MvcSample.Web.Filters;
using MvcSample.Web.Services; using MvcSample.Web.Services;
@ -25,9 +18,7 @@ namespace MvcSample.Web
{ {
public class Startup public class Startup
{ {
#if DNX451
private bool _autoFac; private bool _autoFac;
#endif
public IServiceProvider ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
@ -48,10 +39,6 @@ namespace MvcSample.Web
services.AddMvcLocalization(LanguageViewLocationExpanderFormat.SubFolder); services.AddMvcLocalization(LanguageViewLocationExpanderFormat.SubFolder);
#if DNX451
// Fully-qualify configuration path to avoid issues in functional tests. Just "config.json" would be fine
// but Configuration uses CallContextServiceLocator.Locator.ServiceProvider to get IApplicationEnvironment.
// Functional tests update that service but not in the static provider.
var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>(); var applicationEnvironment = services.BuildServiceProvider().GetRequiredService<IApplicationEnvironment>();
var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json"); var configurationPath = Path.Combine(applicationEnvironment.ApplicationBasePath, "config.json");
@ -72,9 +59,7 @@ namespace MvcSample.Web
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
// Create the container and use the default application services as a fallback // Create the container and use the default application services as a fallback
AutofacRegistration.Populate( builder.Populate(services);
builder,
services);
builder.RegisterModule<MonitoringModule>(); builder.RegisterModule<MonitoringModule>();
@ -83,7 +68,6 @@ namespace MvcSample.Web
return container.Resolve<IServiceProvider>(); return container.Resolve<IServiceProvider>();
} }
else else
#endif
{ {
return services.BuildServiceProvider(); return services.BuildServiceProvider();
} }
@ -94,12 +78,10 @@ namespace MvcSample.Web
app.UseStatusCodePages(); app.UseStatusCodePages();
app.UseFileServer(); app.UseFileServer();
#if DNX451
if (_autoFac) if (_autoFac)
{ {
app.UseMiddleware<MonitoringMiddlware>(); app.UseMiddleware<MonitoringMiddlware>();
} }
#endif
app.UseRequestLocalization(); app.UseRequestLocalization();
app.UseSession(); app.UseSession();

View File

@ -7,6 +7,7 @@
"warningsAsErrors": true "warningsAsErrors": true
}, },
"dependencies": { "dependencies": {
"Autofac.Framework.DependencyInjection": "4.0.0-*",
"Kestrel": "1.0.0-*", "Kestrel": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*", "Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Localization": "1.0.0-*", "Microsoft.AspNet.Localization": "1.0.0-*",
@ -17,19 +18,19 @@
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Session": "1.0.0-*", "Microsoft.AspNet.Session": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.Configuration.Json": "1.0.0-*",
"Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" } "Microsoft.Framework.PropertyHelper.Sources": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.Framework.NotNullAttribute.Sources": {
"type": "build",
"version": "1.0.0-*"
}
}, },
"frameworks": { "frameworks": {
"dnx451": { "dnx451": { },
"dependencies": { "dnxcore50": { }
"Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-*",
"Microsoft.Framework.Configuration.Json": "1.0.0-*"
}
},
"dnxcore50": {
"dependencies": { }
}
}, },
"exclude": [ "exclude": [
"wwwroot", "wwwroot",

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutofacWebSite; using AutofacWebSite;
@ -34,4 +33,3 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
} }
} }
} }
#endif

View File

@ -14,6 +14,7 @@
"AntiforgeryTokenWebSite": "1.0.0", "AntiforgeryTokenWebSite": "1.0.0",
"ApiExplorerWebSite": "1.0.0", "ApiExplorerWebSite": "1.0.0",
"ApplicationModelWebSite": "1.0.0", "ApplicationModelWebSite": "1.0.0",
"AutofacWebSite": "1.0.0",
"BasicWebSite": "1.0.0", "BasicWebSite": "1.0.0",
"BestEffortLinkGenerationWebSite": "1.0.0", "BestEffortLinkGenerationWebSite": "1.0.0",
"CompositeViewEngineWebSite": "1.0.0", "CompositeViewEngineWebSite": "1.0.0",
@ -35,7 +36,10 @@
"LoggingWebSite": "1.0.0", "LoggingWebSite": "1.0.0",
"LowercaseUrlsWebSite": "1.0.0-*", "LowercaseUrlsWebSite": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Mvc.TestCommon": {
"version": "6.0.0-*",
"type": "build"
},
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*", "Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*",
@ -67,11 +71,7 @@
"test": "xunit.runner.aspnet" "test": "xunit.runner.aspnet"
}, },
"frameworks": { "frameworks": {
"dnx451": { "dnx451": { },
"dependencies": {
"AutofacWebSite": "1.0.0"
}
},
"dnxcore50": { "dnxcore50": {
} }
}, },

View File

@ -3,9 +3,9 @@
using System; using System;
using Autofac; using Autofac;
using Autofac.Framework.DependencyInjection;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Autofac;
namespace AutofacWebSite namespace AutofacWebSite
{ {
@ -18,8 +18,7 @@ namespace AutofacWebSite
services.AddTransient<HelloWorldBuilder>(); services.AddTransient<HelloWorldBuilder>();
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
AutofacRegistration.Populate(builder, builder.Populate(services);
services);
var container = builder.Build(); var container = builder.Build();

View File

@ -4,9 +4,8 @@
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5000" "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5000"
}, },
"dependencies": { "dependencies": {
"Autofac": "3.3.0", "Autofac.Framework.DependencyInjection": "4.0.0-*",
"Kestrel": "1.0.0-*", "Kestrel": "1.0.0-*",
"Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0", "Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*", "Microsoft.AspNet.Server.IIS": "1.0.0-*",
@ -14,7 +13,8 @@
"Microsoft.AspNet.StaticFiles": "1.0.0-*" "Microsoft.AspNet.StaticFiles": "1.0.0-*"
}, },
"frameworks": { "frameworks": {
"dnx451": { } "dnx451": { },
"dnxcore50": { }
}, },
"webroot": "wwwroot" "webroot": "wwwroot"
} }