Fix service collection extensions: New overload having lambda for options, return void and added doc comments.

This commit is contained in:
Kiran Challa 2016-02-17 09:16:30 -08:00
parent 8c64656882
commit 05ff447d7d
1 changed files with 28 additions and 10 deletions

View File

@ -15,15 +15,17 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
public static class RoutingServiceCollectionExtensions
{
public static IServiceCollection AddRouting(this IServiceCollection services)
/// <summary>
/// Adds services required for routing requests.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
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<RouteOptions> configureOptions)
{
services.TryAddTransient<IInlineConstraintResolver, DefaultInlineConstraintResolver>();
services.TryAddSingleton(UrlEncoder.Default);
services.TryAddSingleton<ObjectPoolProvider>(new DefaultObjectPoolProvider());
@ -35,13 +37,29 @@ namespace Microsoft.Extensions.DependencyInjection
});
services.TryAddSingleton(typeof(RoutingMarkerService));
}
if (configureOptions != null)
/// <summary>
/// Adds services required for routing requests.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <param name="configureOptions">The routing options to configure the middleware with.</param>
public static void AddRouting(
this IServiceCollection services,
Action<RouteOptions> 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();
}
}
}