Fix routing service registration
This commit is contained in:
parent
813171a016
commit
1e6ff07ec8
|
|
@ -2,16 +2,20 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Text.Encodings.Web;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class RoutingServices
|
||||
/// <summary>
|
||||
/// Contains extension methods to <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
public static class RoutingServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddRouting(this IServiceCollection services)
|
||||
{
|
||||
return AddRouting(services, null);
|
||||
return AddRouting(services, configureOptions: null);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddRouting(
|
||||
|
|
@ -20,6 +24,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
services.AddOptions();
|
||||
services.TryAddTransient<IInlineConstraintResolver, DefaultInlineConstraintResolver>();
|
||||
services.TryAddSingleton(UrlEncoder.Default);
|
||||
|
||||
if (configureOptions != null)
|
||||
{
|
||||
|
|
@ -29,4 +34,4 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Text.Encodings.Web;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extension methods to <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures a set of <see cref="RouteOptions"/> for the application.
|
||||
/// </summary>
|
||||
/// <param name="services">The services available in the application.</param>
|
||||
/// <param name="setupAction">An action to configure the <see cref="RouteOptions"/>.</param>
|
||||
public static void ConfigureRouting(
|
||||
this IServiceCollection services,
|
||||
Action<RouteOptions> setupAction)
|
||||
{
|
||||
if (setupAction == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(setupAction));
|
||||
}
|
||||
|
||||
services.TryAddSingleton(UrlEncoder.Default);
|
||||
services.Configure(setupAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.OptionsModel;
|
||||
|
|
@ -16,10 +15,10 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
public void ConfigureRouting_ConfiguresOptionsProperly()
|
||||
{
|
||||
// Arrange
|
||||
var services = new ServiceCollection().AddOptions();
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// Act
|
||||
services.ConfigureRouting(options => options.ConstraintMap.Add("foo", typeof(TestRouteConstraint)));
|
||||
services.AddRouting(options => options.ConstraintMap.Add("foo", typeof(TestRouteConstraint)));
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// Assert
|
||||
|
|
|
|||
Loading…
Reference in New Issue