/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Http/Routing/test/UnitTests/LinkParserTestBase.cs
71 строка
2 KB
Shreyas Jejurkar
chore : Remove unwanted `using` statement (#39176)
02 янв 2022, 17:39
Не верифицирован
02 янв 2022, 17:39
c85baf8
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Routing; public abstract class LinkParserTestBase { protected ServiceCollection GetBasicServices() { var services = new ServiceCollection(); services.AddOptions(); services.AddRouting(); services.AddLogging(); return services; } protected virtual void AddAdditionalServices(IServiceCollection services) { } private protected DefaultLinkParser CreateLinkParser(params Endpoint[] endpoints) { return CreateLinkParser(configureServices: null, endpoints); } private protected DefaultLinkParser CreateLinkParser( Action<IServiceCollection> configureServices, params Endpoint[] endpoints) { return CreateLinkParser(configureServices, new[] { new DefaultEndpointDataSource(endpoints ?? Array.Empty<Endpoint>()) }); } private protected DefaultLinkParser CreateLinkParser(EndpointDataSource[] dataSources) { return CreateLinkParser(configureServices: null, dataSources); } private protected DefaultLinkParser CreateLinkParser( Action<IServiceCollection> configureServices, EndpointDataSource[] dataSources) { var services = GetBasicServices(); AddAdditionalServices(services); configureServices?.Invoke(services); services.Configure<RouteOptions>(o => { if (dataSources != null) { foreach (var dataSource in dataSources) { o.EndpointDataSources.Add(dataSource); } } }); var serviceProvider = services.BuildServiceProvider(); var routeOptions = serviceProvider.GetRequiredService<IOptions<RouteOptions>>(); return new DefaultLinkParser( new DefaultParameterPolicyFactory(routeOptions, serviceProvider), new CompositeEndpointDataSource(routeOptions.Value.EndpointDataSources), serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger<DefaultLinkParser>(), serviceProvider); } }