diff --git a/src/Microsoft.AspNetCore.Routing/DependencyInjection/RoutingServiceCollectionExtensions.cs b/src/Microsoft.AspNetCore.Routing/DependencyInjection/RoutingServiceCollectionExtensions.cs
index 2425ed668c..8ae1392aee 100644
--- a/src/Microsoft.AspNetCore.Routing/DependencyInjection/RoutingServiceCollectionExtensions.cs
+++ b/src/Microsoft.AspNetCore.Routing/DependencyInjection/RoutingServiceCollectionExtensions.cs
@@ -15,15 +15,17 @@ namespace Microsoft.Extensions.DependencyInjection
///
public static class RoutingServiceCollectionExtensions
{
- public static IServiceCollection AddRouting(this IServiceCollection services)
+ ///
+ /// Adds services required for routing requests.
+ ///
+ /// The to add the services to.
+ public static void AddRouting(this IServiceCollection services)
{
- return AddRouting(services, configureOptions: null);
- }
+ if (services == null)
+ {
+ throw new ArgumentNullException(nameof(services));
+ }
- public static IServiceCollection AddRouting(
- this IServiceCollection services,
- Action configureOptions)
- {
services.TryAddTransient();
services.TryAddSingleton(UrlEncoder.Default);
services.TryAddSingleton(new DefaultObjectPoolProvider());
@@ -35,13 +37,29 @@ namespace Microsoft.Extensions.DependencyInjection
});
services.TryAddSingleton(typeof(RoutingMarkerService));
+ }
- if (configureOptions != null)
+ ///
+ /// Adds services required for routing requests.
+ ///
+ /// The to add the services to.
+ /// The routing options to configure the middleware with.
+ public static void AddRouting(
+ this IServiceCollection services,
+ Action configureOptions)
+ {
+ if (services == null)
{
- services.Configure(configureOptions);
+ throw new ArgumentNullException(nameof(services));
}
- return services;
+ if (configureOptions == null)
+ {
+ throw new ArgumentNullException(nameof(configureOptions));
+ }
+
+ services.Configure(configureOptions);
+ services.AddRouting();
}
}
}
\ No newline at end of file