Cleaned up the mvc sample
- Removed unnecessary dependencies - Removed web.config - Use overload of UseServices that automatically adds options
This commit is contained in:
parent
70e809a430
commit
18400481b5
|
|
@ -31,32 +31,33 @@ namespace MvcSample.Web
|
||||||
{
|
{
|
||||||
app.UseMiddleware<MonitoringMiddlware>();
|
app.UseMiddleware<MonitoringMiddlware>();
|
||||||
|
|
||||||
var services = new ServiceCollection();
|
app.UseServices(services =>
|
||||||
|
{
|
||||||
|
services.AddMvc();
|
||||||
|
services.AddSingleton<PassThroughAttribute>();
|
||||||
|
services.AddSingleton<UserNameService>();
|
||||||
|
services.AddTransient<ITestService, TestService>();
|
||||||
|
|
||||||
services.AddMvc();
|
// Setup services with a test AssemblyProvider so that only the
|
||||||
services.AddSingleton<PassThroughAttribute>();
|
// sample's assemblies are loaded. This prevents loading controllers from other assemblies
|
||||||
services.AddSingleton<UserNameService>();
|
// when the sample is used in the Functional Tests.
|
||||||
services.AddTransient<ITestService, TestService>();
|
services.AddTransient<IControllerAssemblyProvider, TestAssemblyProvider<Startup>>();
|
||||||
services.Add(OptionsServices.GetDefaultServices());
|
|
||||||
// Setup services with a test AssemblyProvider so that only the
|
|
||||||
// sample's assemblies are loaded. This prevents loading controllers from other assemblies
|
|
||||||
// when the sample is used in the Functional Tests.
|
|
||||||
services.AddTransient<IControllerAssemblyProvider, TestAssemblyProvider<Startup>>();
|
|
||||||
|
|
||||||
// Create the autofac container
|
// Create the autofac container
|
||||||
ContainerBuilder builder = new ContainerBuilder();
|
ContainerBuilder 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(
|
AutofacRegistration.Populate(
|
||||||
builder,
|
builder,
|
||||||
services,
|
services,
|
||||||
fallbackServiceProvider: app.ApplicationServices);
|
fallbackServiceProvider: app.ApplicationServices);
|
||||||
|
|
||||||
builder.RegisterModule<MonitoringModule>();
|
builder.RegisterModule<MonitoringModule>();
|
||||||
|
|
||||||
IContainer container = builder.Build();
|
IContainer container = builder.Build();
|
||||||
|
|
||||||
app.UseServices(container.Resolve<IServiceProvider>());
|
return container.Resolve<IServiceProvider>();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,31 +13,19 @@
|
||||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
||||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
||||||
"Microsoft.DataAnnotations": "1.0.0-*",
|
"Microsoft.DataAnnotations": "1.0.0-*",
|
||||||
"Microsoft.Framework.ConfigurationModel": "1.0.0-*",
|
"Microsoft.Framework.ConfigurationModel": "1.0.0-*"
|
||||||
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
|
|
||||||
"Microsoft.Framework.OptionsModel": "1.0.0-*"
|
|
||||||
},
|
},
|
||||||
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
|
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"aspnet50": {
|
"aspnet50": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.ComponentModel.DataAnnotations": "",
|
|
||||||
"Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-*",
|
"Microsoft.Framework.DependencyInjection.Autofac": "1.0.0-*",
|
||||||
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
|
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
|
||||||
"Autofac": "3.3.0"
|
"Autofac": "3.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"aspnetcore50": {
|
"aspnetcore50": {
|
||||||
"dependencies": {
|
"dependencies": { }
|
||||||
"System.ComponentModel": "4.0.0.0",
|
|
||||||
"System.Console": "4.0.0.0",
|
|
||||||
"System.Diagnostics.Debug": "4.0.10.0",
|
|
||||||
"System.Diagnostics.Tools": "4.0.0.0",
|
|
||||||
"System.Dynamic.Runtime": "4.0.0.0",
|
|
||||||
"System.Runtime": "4.0.20.0",
|
|
||||||
"System.Runtime.InteropServices": "4.0.20.0",
|
|
||||||
"System.Threading.Tasks": "4.0.10.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
|
||||||
|
|
||||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
|
||||||
<!--
|
|
||||||
In the example below, the "SetAttributes" transform will change the value of
|
|
||||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
|
||||||
finds an attribute "name" that has a value of "MyDB".
|
|
||||||
|
|
||||||
<connectionStrings>
|
|
||||||
<add name="MyDB"
|
|
||||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
|
||||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
|
||||||
</connectionStrings>
|
|
||||||
-->
|
|
||||||
<system.web>
|
|
||||||
<!--
|
|
||||||
In the example below, the "Replace" transform will replace the entire
|
|
||||||
<customErrors> section of your web.config file.
|
|
||||||
Note that because there is only one customErrors section under the
|
|
||||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
|
||||||
|
|
||||||
<customErrors defaultRedirect="GenericError.htm"
|
|
||||||
mode="RemoteOnly" xdt:Transform="Replace">
|
|
||||||
<error statusCode="500" redirect="InternalError.htm"/>
|
|
||||||
</customErrors>
|
|
||||||
-->
|
|
||||||
</system.web>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
|
||||||
|
|
||||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
|
||||||
<!--
|
|
||||||
In the example below, the "SetAttributes" transform will change the value of
|
|
||||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
|
||||||
finds an attribute "name" that has a value of "MyDB".
|
|
||||||
|
|
||||||
<connectionStrings>
|
|
||||||
<add name="MyDB"
|
|
||||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
|
||||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
|
||||||
</connectionStrings>
|
|
||||||
-->
|
|
||||||
<system.web>
|
|
||||||
<compilation xdt:Transform="RemoveAttributes(debug)" />
|
|
||||||
<!--
|
|
||||||
In the example below, the "Replace" transform will replace the entire
|
|
||||||
<customErrors> section of your web.config file.
|
|
||||||
Note that because there is only one customErrors section under the
|
|
||||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
|
||||||
|
|
||||||
<customErrors defaultRedirect="GenericError.htm"
|
|
||||||
mode="RemoteOnly" xdt:Transform="Replace">
|
|
||||||
<error statusCode="500" redirect="InternalError.htm"/>
|
|
||||||
</customErrors>
|
|
||||||
-->
|
|
||||||
</system.web>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<configuration>
|
|
||||||
<appSettings>
|
|
||||||
<add key="K" value="false" />
|
|
||||||
</appSettings>
|
|
||||||
<system.web>
|
|
||||||
<compilation debug="true" targetFramework="4.5" />
|
|
||||||
<httpRuntime targetFramework="4.5" />
|
|
||||||
</system.web>
|
|
||||||
|
|
||||||
</configuration>
|
|
||||||
Loading…
Reference in New Issue