本文整理汇总了C#中Microsoft.Framework.DependencyInjection.ServiceCollection.ConfigureOptions方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.ConfigureOptions方法的具体用法?C# ServiceCollection.ConfigureOptions怎么用?C# ServiceCollection.ConfigureOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Framework.DependencyInjection.ServiceCollection
的用法示例。
在下文中一共展示了ServiceCollection.ConfigureOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupCallsInOrder
public void SetupCallsInOrder()
{
var services = new ServiceCollection().AddOptions();
var dic = new Dictionary<string, string>
{
{"Message", "!"},
};
var builder = new ConfigurationBuilder().AddInMemoryCollection(dic);
var config = builder.Build();
services.Configure<FakeOptions>(o => o.Message += "Igetstomped");
services.Configure<FakeOptions>(config);
services.Configure<FakeOptions>(o => o.Message += "a");
services.ConfigureOptions(typeof(FakeOptionsSetupA));
services.ConfigureOptions(new FakeOptionsSetupB());
services.ConfigureOptions<FakeOptionsSetupC>();
services.Configure<FakeOptions>(o => o.Message += "z");
var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();
Assert.NotNull(service);
var options = service.Value;
Assert.NotNull(options);
Assert.Equal("!aABCz", options.Message);
}
示例2: NamedSetupDoNotCollideWithEachOther
public void NamedSetupDoNotCollideWithEachOther()
{
var services = new ServiceCollection().AddOptions();
var dic = new Dictionary<string, string>
{
{"Message", "!"},
};
var builder = new ConfigurationBuilder(new MemoryConfigurationSource(dic));
var config = builder.Build();
services.ConfigureOptions(new FakeOptionsSetupB { Name = "2" });
services.Configure<FakeOptions>(o => o.Message += "Z", 10000, "2");
services.ConfigureOptions(new FakeOptionsSetupB { Name = "3" });
services.Configure<FakeOptions>(config, "3");
services.Configure<FakeOptions>(o => o.Message += "z", 10000, "3");
var service = services.BuildServiceProvider().GetService<IOptions<FakeOptions>>();
Assert.NotNull(service);
var options = service.Options;
Assert.NotNull(options);
Assert.Equal("", options.Message);
var options2 = service.GetNamedOptions("2");
Assert.NotNull(options2);
Assert.Equal("BZ", options2.Message);
var options3 = service.GetNamedOptions("3");
Assert.NotNull(options3);
Assert.Equal("!Bz", options3.Message);
}