本文整理汇总了C#中ServiceCollection.AddRouting方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.AddRouting方法的具体用法?C# ServiceCollection.AddRouting怎么用?C# ServiceCollection.AddRouting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceCollection
的用法示例。
在下文中一共展示了ServiceCollection.AddRouting方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureRouting_ConfiguresOptionsProperly
public void ConfigureRouting_ConfiguresOptionsProperly()
{
// Arrange
var services = new ServiceCollection();
services.AddOptions();
// Act
services.AddRouting(options => options.ConstraintMap.Add("foo", typeof(TestRouteConstraint)));
var serviceProvider = services.BuildServiceProvider();
// Assert
var accessor = serviceProvider.GetRequiredService<IOptions<RouteOptions>>();
Assert.Equal("TestRouteConstraint", accessor.Value.ConstraintMap["foo"].Name);
}
示例2: CreateVirtualPathContext
private static VirtualPathContext CreateVirtualPathContext(
RouteValueDictionary values,
RouteValueDictionary ambientValues)
{
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddRouting();
var context = new DefaultHttpContext
{
RequestServices = services.BuildServiceProvider(),
};
return new VirtualPathContext(context, ambientValues, values);
}
示例3: CreateServices
private static IServiceProvider CreateServices()
{
var services = new ServiceCollection();
services.AddOptions();
services.AddLogging();
services.AddRouting();
services
.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
.AddSingleton<UrlEncoder>(UrlEncoder.Default);
return services.BuildServiceProvider();
}
示例4: CreateVirtualPathContext
private static VirtualPathContext CreateVirtualPathContext(
RouteValueDictionary values,
Action<RouteOptions> options = null,
string routeName = null)
{
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
services.AddOptions();
services.AddRouting();
if (options != null)
{
services.Configure<RouteOptions>(options);
}
var context = new DefaultHttpContext
{
RequestServices = services.BuildServiceProvider(),
};
return new VirtualPathContext(
context,
ambientValues: null,
values: values,
routeName: routeName);
}
示例5: GetServiceCollection
private static ServiceCollection GetServiceCollection(IStringLocalizerFactory localizerFactory)
{
var serviceCollection = new ServiceCollection();
serviceCollection
.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
.AddSingleton<ILoggerFactory>(new NullLoggerFactory())
.AddSingleton<UrlEncoder>(new UrlTestEncoder());
serviceCollection.AddOptions();
serviceCollection.AddRouting();
serviceCollection.AddSingleton<IInlineConstraintResolver>(
provider => new DefaultInlineConstraintResolver(provider.GetRequiredService<IOptions<RouteOptions>>()));
if (localizerFactory != null)
{
serviceCollection.AddSingleton<IStringLocalizerFactory>(localizerFactory);
}
return serviceCollection;
}
示例6: GetServiceCollection
private static ServiceCollection GetServiceCollection()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<ILoggerFactory>(new NullLoggerFactory());
serviceCollection.AddSingleton<UrlEncoder>(new UrlTestEncoder());
var routeOptions = new RouteOptions();
var accessor = new Mock<IOptions<RouteOptions>>();
accessor
.SetupGet(options => options.Value)
.Returns(routeOptions);
serviceCollection.AddSingleton<IOptions<RouteOptions>>(accessor.Object);
serviceCollection.AddRouting();
serviceCollection.AddSingleton<IInlineConstraintResolver>(
new DefaultInlineConstraintResolver(accessor.Object));
return serviceCollection;
}
示例7: CreateServices
private IServiceProvider CreateServices()
{
var services = new ServiceCollection();
services.AddOptions();
services.AddRouting();
return services.BuildServiceProvider();
}