diff --git a/samples/MvcSample.Web/App_Data/Config.json b/samples/MvcSample.Web/App_Data/Config.json
new file mode 100644
index 0000000000..f8463dd38a
--- /dev/null
+++ b/samples/MvcSample.Web/App_Data/Config.json
@@ -0,0 +1,3 @@
+{
+ "DependencyInjection": "AutoFac"
+}
\ No newline at end of file
diff --git a/samples/MvcSample.Web/MvcSample.Web.kproj b/samples/MvcSample.Web/MvcSample.Web.kproj
index 0f9dbe9769..2f58638eb8 100644
--- a/samples/MvcSample.Web/MvcSample.Web.kproj
+++ b/samples/MvcSample.Web/MvcSample.Web.kproj
@@ -23,6 +23,7 @@
42750
+
diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs
index 40508cdc84..cdedc534a5 100644
--- a/samples/MvcSample.Web/Startup.cs
+++ b/samples/MvcSample.Web/Startup.cs
@@ -1,24 +1,65 @@
-using Microsoft.AspNet;
+using System;
using Microsoft.AspNet.Builder;
-using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using MvcSample.Web.Filters;
using MvcSample.Web.Services;
+#if NET45
+using Autofac;
+using Microsoft.Framework.DependencyInjection.Autofac;
+using Microsoft.Framework.ConfigurationModel;
+using Microsoft.Framework.OptionsModel;
+#endif
+
namespace MvcSample.Web
{
public class Startup
{
public void Configure(IBuilder app)
{
- app.UseServices(services =>
+#if NET45
+ var configuration = new Configuration()
+ .AddJsonFile(@"App_Data\config.json")
+ .AddEnvironmentVariables();
+
+ string diSystem;
+
+ if (configuration.TryGet("DependencyInjection", out diSystem) &&
+ diSystem.Equals("AutoFac", StringComparison.OrdinalIgnoreCase))
{
+ var services = new ServiceCollection();
+
services.AddMvc();
services.AddSingleton();
services.AddSingleton();
- services.AddTransient();
- });
+ services.AddTransient();
+ services.Add(OptionsServices.GetDefaultServices());
+
+ // Create the autofac container
+ ContainerBuilder builder = new ContainerBuilder();
+
+ // Create the container and use the default application services as a fallback
+ AutofacRegistration.Populate(
+ builder,
+ services,
+ fallbackServiceProvider: app.ApplicationServices);
+
+ IContainer container = builder.Build();
+
+ app.UseServices(container.Resolve());
+ }
+ else
+#endif
+ {
+ app.UseServices(services =>
+ {
+ services.AddMvc();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddTransient();
+ });
+ }
app.UseMvc(routes =>
{
diff --git a/samples/MvcSample.Web/project.json b/samples/MvcSample.Web/project.json
index f9d12d7fb3..31a6d8620a 100644
--- a/samples/MvcSample.Web/project.json
+++ b/samples/MvcSample.Web/project.json
@@ -14,13 +14,17 @@
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
"Microsoft.DataAnnotations": "0.1-alpha-*",
"Microsoft.Framework.ConfigurationModel": "0.1-alpha-*",
- "Microsoft.Framework.DependencyInjection": "0.1-alpha-*"
+ "Microsoft.Framework.DependencyInjection": "0.1-alpha-*",
+ "Microsoft.Framework.OptionsModel": "0.1-alpha-*"
},
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
"configurations": {
"net45": {
"dependencies": {
- "System.ComponentModel.DataAnnotations": ""
+ "System.ComponentModel.DataAnnotations": "",
+ "Microsoft.Framework.DependencyInjection.Autofac": "0.1-alpha-*",
+ "Microsoft.Framework.ConfigurationModel.Json": "0.1-alpha-*",
+ "Autofac": "3.3.0"
}
},
"k10": {