本文整理汇总了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);
}
示例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"));
}
示例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])));
}
}
示例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])));
}
}
}