Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Modify BuilderExtensions.UseMvc to not add any routes by default #1880

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions samples/MvcSample.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using System.Security.Claims;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Security;
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
Expand Down
7 changes: 6 additions & 1 deletion samples/TagHelperSample.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ public void Configure(IApplicationBuilder app)
options.AddXmlDataContractSerializerFormatter();
});
});
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
21 changes: 16 additions & 5 deletions src/Microsoft.AspNet.Mvc/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@

namespace Microsoft.AspNet.Builder
{
/// <summary>
/// Extension methods for <see cref="IApplicationBuilder"/> to add Mvc to the request execution pipeline.
/// </summary>
public static class BuilderExtensions
{
/// <summary>
/// Adds Mvc to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns>
/// <remarks>This method only supports attribute routing. To add conventional routes use
/// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks>
public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should docs include <remarks/> describing expectation application uses attribute routes exclusively?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh, not super sure on this - remarks shouldn't be a place for specifying application design guidance. This sounds more like a sample \ doc thing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we could say something here without it being design guidance.

UseMvc() only supports attribute routing. To add conventional routes use AddMvc(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

{
return app.UseMvc(routes =>
{
// Action style actions
routes.MapRoute(null, "{controller}/{action}/{id?}", new { controller = "Home", action = "Index" });

// Rest style actions
routes.MapRoute(null, "{controller}/{id?}");
});
}

/// <summary>
/// Adds Mvc to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="configureRoutes">A callback to configure Mvc routes.</param>
/// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvc(
[NotNull] this IApplicationBuilder app,
[NotNull] Action<IRouteBuilder> configureRoutes)
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/ActionConstraintsWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace ActionConstraintsWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/ActionResultsWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace ActionResultsWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/ActivatorWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace ActivatorWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/AddServicesWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;

namespace AddServicesWebSite
{
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/AntiForgeryWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace AntiForgeryWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/ApiExplorerWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so this'll go in after your Routing change?


namespace ApiExplorerWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/ApplicationModelWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public void Configure(IApplicationBuilder app)
services.AddMvc(configuration);
});

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/AutofacWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using Autofac;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Autofac;

Expand Down
1 change: 0 additions & 1 deletion test/WebSites/BasicWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace BasicWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/CompositeViewEngineWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public void Configure(IApplicationBuilder app)
});

// Add MVC to the request pipeline
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/ConnegWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace ConnegWebSite
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/CustomRouteWebSite/LocalizedRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;

namespace CustomRouteWebSite
{
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/CustomRouteWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace CustomRouteWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/FilesWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace FilesWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/FiltersWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public void Configure(IApplicationBuilder app)

app.UseMiddleware<AuthorizeBasicMiddleware>();

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/FormatterWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace FormatterWebSite
Expand Down
1 change: 0 additions & 1 deletion test/WebSites/InlineConstraintsWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.Framework.DependencyInjection;

Expand Down
1 change: 0 additions & 1 deletion test/WebSites/LoggingWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace LoggingWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/ModelBindingWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public void Configure(IApplicationBuilder app)
app.UseErrorReporter();

// Add MVC to the request pipeline
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/MvcTagHelpersWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace MvcTagHelpersWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/PrecompilationWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public void Configure(IApplicationBuilder app)
services.AddMvc(configuration);
});

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
7 changes: 6 additions & 1 deletion test/WebSites/RazorInstrumentationWebsite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public void Configure(IApplicationBuilder app)
});

// Add MVC to the request pipeline
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
2 changes: 0 additions & 2 deletions test/WebSites/RazorViewEngineOptionsWebsite/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.IO;
using System.Reflection;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Razor;
using Microsoft.Framework.DependencyInjection;
using Microsoft.AspNet.Routing;

namespace RazorViewEngineOptionsWebsite
{
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/RazorWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public void Configure(IApplicationBuilder app)
});

// Add MVC to the request pipeline
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
7 changes: 6 additions & 1 deletion test/WebSites/RequestServicesWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public void Configure(IApplicationBuilder app)
// Initializes the RequestId service for each request
app.UseMiddleware<RequestIdMiddleware>();

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
7 changes: 6 additions & 1 deletion test/WebSites/ResponseCacheWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public void Configure(IApplicationBuilder app)
services.AddMvc(configuration);
});

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/RoutingWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace RoutingWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/TagHelpersWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public void Configure(IApplicationBuilder app)
services.AddMvc(configuration);
});

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
1 change: 0 additions & 1 deletion test/WebSites/UrlHelperWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

namespace UrlHelperWebSite
Expand Down
7 changes: 6 additions & 1 deletion test/WebSites/ValueProvidersWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public void Configure(IApplicationBuilder app)
});

// Add MVC to the request pipeline
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
7 changes: 6 additions & 1 deletion test/WebSites/VersioningWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public void Configure(IApplicationBuilder app)
services.AddScoped<TestResponseGenerator>();
});

app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Loading