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


C# ServiceCollection.CutoffPrevious方法代码示例

本文整理汇总了C#中ServiceCollection.CutoffPrevious方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.CutoffPrevious方法的具体用法?C# ServiceCollection.CutoffPrevious怎么用?C# ServiceCollection.CutoffPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceCollection的用法示例。


在下文中一共展示了ServiceCollection.CutoffPrevious方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigurationRegistersHookPointsCorrectly

        public void ConfigurationRegistersHookPointsCorrectly()
        {
            IServiceCollection services = new ServiceCollection();
            var configuration = services.BuildApiConfiguration();

            Assert.Null(configuration.GetApiService<IHookA>());
            Assert.Null(configuration.GetApiService<IHookB>());

            var singletonHookPoint = new HookA();
            services.CutoffPrevious<IHookA>(singletonHookPoint);
            configuration = services.BuildApiConfiguration();
            Assert.Same(singletonHookPoint, configuration.GetApiService<IHookA>());
            Assert.Null(configuration.GetApiService<IHookB>());

            var multiCastHookPoint1 = new HookB();
            services.CutoffPrevious<IHookB>(multiCastHookPoint1);
            configuration = services.BuildApiConfiguration();
            Assert.Same(singletonHookPoint, configuration.GetApiService<IHookA>());
            Assert.Equal(multiCastHookPoint1, configuration.GetApiService<IHookB>());

            services = new ServiceCollection()
                .CutoffPrevious<IHookB>(multiCastHookPoint1)
                .ChainPrevious<IHookB, HookB>()
                .AddInstance(new HookB());
            configuration = services.BuildApiConfiguration();
            var multiCastHookPoint2 = configuration.GetApiService<HookB>();
            var handler = configuration.GetApiService<IHookB>();
            Assert.Equal(multiCastHookPoint2, handler);

            var delegateHandler = handler as HookB;
            Assert.NotNull(delegateHandler);
            Assert.Equal(multiCastHookPoint1, delegateHandler.InnerHandler);
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:33,代码来源:ApiConfiguration.Tests.cs

示例2: GetModelUsingDefaultModelHandler

        public async Task GetModelUsingDefaultModelHandler()
        {
            var services = new ServiceCollection();
            services.CutoffPrevious<IModelBuilder>(new TestModelProducer());
            services.ChainPrevious<IModelBuilder>(next => new TestModelExtender(2)
            {
                InnerHandler = next,
            });
            services.ChainPrevious<IModelBuilder>(next => new TestModelExtender(3)
            {
                InnerHandler = next,
            });

            var configuration = services.BuildApiConfiguration();
            var context = new ApiContext(configuration);

            var model = await context.GetModelAsync();
            Assert.Equal(4, model.SchemaElements.Count());
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName"));
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName2"));
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName3"));
            Assert.NotNull(model.EntityContainer);
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet"));
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet2"));
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet3"));
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:32,代码来源:DefaultModelHandler.Tests.cs

示例3: GetModelAsyncRetriableAfterFailure

        public async Task GetModelAsyncRetriableAfterFailure()
        {
            var services = new ServiceCollection();
            var service = new TestRetryModelBuilder();
            services.CutoffPrevious<IModelBuilder>(service);
            var configuration = services.BuildApiConfiguration();

            using (var wait = new ManualResetEventSlim(false))
            {
                var tasks = PrepareThreads(6, configuration, wait);
                wait.Set();

                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Assert.True(t.IsFaulted);
                    Assert.True(tasks.All(e => e.IsFaulted));
                });
                Assert.Equal(1, service.CalledCount);

                tasks = PrepareThreads(150, configuration, wait);

                var models = await Task.WhenAll(tasks);
                Assert.Equal(2, service.CalledCount);
                Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
            }
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:26,代码来源:DefaultModelHandler.Tests.cs

示例4: ModelBuilderShouldBeCalledOnlyOnceIfSucceeded

        public async Task ModelBuilderShouldBeCalledOnlyOnceIfSucceeded()
        {
            var services = new ServiceCollection();
            var service = new TestSingleCallModelBuilder();
            services.CutoffPrevious<IModelBuilder>(service);
            var configuration = services.BuildApiConfiguration();

            using (var wait = new ManualResetEventSlim(false))
            {
                for (int i = 0; i < 2; i++)
                {
                    var tasks = PrepareThreads(50, configuration, wait);
                    wait.Set();

                    var models = await Task.WhenAll(tasks);
                    Assert.Equal(1, service.CalledCount);
                    Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
                }
            }
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:20,代码来源:DefaultModelHandler.Tests.cs


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