本文整理汇总了C#中Autofac.ContainerBuilder.RegisterSwitchedType方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterSwitchedType方法的具体用法?C# ContainerBuilder.RegisterSwitchedType怎么用?C# ContainerBuilder.RegisterSwitchedType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.RegisterSwitchedType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_keep_both_containers_separated_by_scope
public void Should_keep_both_containers_separated_by_scope()
{
var builder = new ContainerBuilder();
builder.RegisterSwitchedType<BigOn, A, BigA, LittleA>();
// builder.RegisterType<DefaultDataProvider>()
// .As<IDataProvider>()
// .SingleInstance();
//
// using (var container = builder.Build())
// {
// var provider = container.Resolve<IDataProvider>();
// Assert.AreEqual("Default", provider.GetData());
//
// var tenent = container.BeginLifetimeScope(x =>
// {
// x.RegisterType<UpperCaseDataTransformer>()
// .As<IDataTransformer>();
// x.RegisterType<CustomDataProvider>()
// .As<IDataProvider>()
// .SingleInstance();
// });
//
// using(tenent)
// {
// var custom = container.Resolve<IDataProvider>();
// Assert.AreEqual("Custom", custom.GetData());
//
// string upper = tenent.Resolve<IDataTransformer>().Transform("John");
// Assert.AreEqual("JOHN", upper);
// }
//
// string lower = container.Resolve<IDataTransformer>().Transform("John");
// Assert.AreEqual("john", lower);
// }
}
示例2: Should_return_original_registration_by_type
public void Should_return_original_registration_by_type()
{
var builder = new ContainerBuilder();
builder.RegisterCodeSwitchDisabled<UseClassAv2>();
builder.RegisterSwitchedType<UseClassAv2, A, ClassA_V2, ClassA>();
IContainer container = builder.Build();
var a = container.Resolve<A>();
Assert.IsInstanceOf<ClassA>(a);
}
示例3: Setup
public void Setup()
{
var builder = new ContainerBuilder();
builder.RegisterCodeSwitchToggle<UseNewCodePath>();
builder.RegisterCodeSwitchToggle<UseNewClass>();
builder.EnableCodeSwitchTracking();
builder.RegisterType<Logger>()
.As<ILogger>();
builder.RegisterSwitchedType<UseNewClass, IClass, TestClassV2, TestClass>();
builder.RegisterType<TestClass>();
_container = builder.Build();
}