// 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.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.ObjectPool; namespace Microsoft.Extensions.DependencyInjection { /// /// Contains extension methods to . /// public static class RoutingServiceCollectionExtensions { public static IServiceCollection AddRouting(this IServiceCollection services) { return AddRouting(services, configureOptions: null); } public static IServiceCollection AddRouting( this IServiceCollection services, Action configureOptions) { services.TryAddTransient(); services.TryAddSingleton(UrlEncoder.Default); services.TryAddSingleton(new DefaultObjectPoolProvider()); services.TryAddSingleton>(s => { var provider = s.GetRequiredService(); var encoder = s.GetRequiredService(); return provider.Create(new UriBuilderContextPooledObjectPolicy(encoder)); }); services.TryAddSingleton(typeof(RoutingMarkerService)); if (configureOptions != null) { services.Configure(configureOptions); } return services; } } }