当前位置: 首页>>代码示例>>C#>>正文


C# ServiceCollection.AddRouting方法代码示例

本文整理汇总了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);
        }
开发者ID:leloulight,项目名称:Routing,代码行数:14,代码来源:RouteOptionsTests.cs

示例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);
        }
开发者ID:leloulight,项目名称:Routing,代码行数:15,代码来源:RouteTest.cs

示例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();
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:12,代码来源:UrlHelperTest.cs

示例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);
        }
开发者ID:Corays,项目名称:Routing,代码行数:26,代码来源:RouteCollectionTest.cs

示例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;
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:21,代码来源:RemoteAttributeTest.cs

示例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;
        }
开发者ID:phinq19,项目名称:git_example,代码行数:20,代码来源:RemoteAttributeTest.cs

示例7: CreateServices

 private IServiceProvider CreateServices()
 {
     var services = new ServiceCollection();
     services.AddOptions();
     services.AddRouting();
     return services.BuildServiceProvider();
 }
开发者ID:phinq19,项目名称:git_example,代码行数:7,代码来源:MvcAreaRouteBuilderExtensionsTest.cs


注:本文中的ServiceCollection.AddRouting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。