本文整理汇总了C#中Autofac.ContainerBuilder.BeginLifetimeScope方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.BeginLifetimeScope方法的具体用法?C# ContainerBuilder.BeginLifetimeScope怎么用?C# ContainerBuilder.BeginLifetimeScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.BeginLifetimeScope方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_register_service_level_component_at_service_scope_creation_and_resolve_in_service_scope
public void Can_register_service_level_component_at_service_scope_creation_and_resolve_in_service_scope()
{
var hostScope = new ContainerBuilder().Build(ContainerBuildOptions.Default).BeginLifetimeScope(DreamContainerScope.Host);
var serviceScope = hostScope.BeginLifetimeScope(DreamContainerScope.Service, b => b.RegisterType<Foo>().As<IFoo>().ServiceScoped());
var foo = serviceScope.Resolve<IFoo>();
Assert.IsNotNull(foo);
}
示例2: Cannot_resolve_RequestScoped_component_registered_at_service_scope_creation_in_service_scope
public void Cannot_resolve_RequestScoped_component_registered_at_service_scope_creation_in_service_scope()
{
var hostScope = new ContainerBuilder().Build(ContainerBuildOptions.Default).BeginLifetimeScope(DreamContainerScope.Host);
var serviceScope = hostScope.BeginLifetimeScope(DreamContainerScope.Service, b => b.RegisterType<Foo>().As<IFoo>().RequestScoped());
try {
var foo = serviceScope.Resolve<IFoo>();
} catch(DependencyResolutionException e) {
return;
}
Assert.Fail("resolved component in wrong scope");
}
示例3: Build_SingleActionRegistered
public void Build_SingleActionRegistered()
{
var builder = new ConfigurationActionBuilder();
builder.Add(b => b.RegisterType<StubDependency1Impl1>().As<IStubDependency1>());
var built = builder.Build();
var container = new ContainerBuilder().Build();
using (var scope = container.BeginLifetimeScope(built))
{
Assert.IsInstanceOf<StubDependency1Impl1>(scope.Resolve<IStubDependency1>(), "The registered lambda did not execute.");
}
}
示例4: Last_registration_wins
public void Last_registration_wins()
{
var hostScope = new ContainerBuilder().Build(ContainerBuildOptions.Default).BeginLifetimeScope(DreamContainerScope.Host);
var serviceScope = hostScope.BeginLifetimeScope(DreamContainerScope.Service, b => {
b.RegisterType<Foo>().As<IFoo>().ServiceScoped();
b.RegisterType<Fu>().As<IFoo>().ServiceScoped();
});
var foo = serviceScope.Resolve<IFoo>();
Assert.AreEqual(typeof(Fu), foo.GetType());
}
示例5: Last_module_wins
public void Last_module_wins()
{
var hostScope = new ContainerBuilder().Build(ContainerBuildOptions.None).BeginLifetimeScope(DreamContainerScope.Host);
var serviceScope = hostScope.BeginLifetimeScope(DreamContainerScope.Service, b => {
b.RegisterModule(new FooModule());
b.RegisterModule(new FuModule());
});
var foo = serviceScope.Resolve<IFoo>();
Assert.AreEqual(typeof(Fu), foo.GetType());
}