本文整理汇总了C#中ContainerBuilder.BeginLifetimeScope方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.BeginLifetimeScope方法的具体用法?C# ContainerBuilder.BeginLifetimeScope怎么用?C# ContainerBuilder.BeginLifetimeScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.BeginLifetimeScope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegistrationsMadeByUpdatingAChildScopeDoNotAppearInTheParentScope
public void RegistrationsMadeByUpdatingAChildScopeDoNotAppearInTheParentScope()
{
var container = new ContainerBuilder().Build();
var childScope = container.BeginLifetimeScope();
var updater = new ContainerBuilder();
updater.RegisterType<object>();
updater.Update(childScope.ComponentRegistry);
Assert.True(childScope.IsRegistered<object>());
Assert.False(container.IsRegistered<object>());
}
示例2: ComponentsInNestedLifetimeCanResolveDependenciesFromParent
public void ComponentsInNestedLifetimeCanResolveDependenciesFromParent()
{
var level1Scope = new ContainerBuilder().Build();
var level2Scope = level1Scope.BeginLifetimeScope(cb =>
cb.RegisterType<AddressBook>());
var level3Scope = level2Scope.BeginLifetimeScope(cb =>
cb.RegisterType<Person>());
level3Scope.Resolve<AddressBook>().Add();
}
示例3: InstancesRegisteredInNestedScopeAreSingletonsInThatScope
public void InstancesRegisteredInNestedScopeAreSingletonsInThatScope()
{
var rootScope = new ContainerBuilder().Build();
var dt = new DisposeTracker();
var nestedScope = rootScope.BeginLifetimeScope(cb =>
cb.RegisterInstance(dt));
var dt1 = nestedScope.Resolve<DisposeTracker>();
Assert.AreSame(dt, dt1);
}
示例4: SingletonsRegisteredInNestedScopeAreTiedToThatScope
public void SingletonsRegisteredInNestedScopeAreTiedToThatScope()
{
var rootScope = new ContainerBuilder().Build();
var nestedScope = rootScope.BeginLifetimeScope(cb =>
cb.RegisterType<DisposeTracker>().SingleInstance());
var dt = nestedScope.Resolve<DisposeTracker>();
var dt1 = nestedScope.Resolve<DisposeTracker>();
Assert.Same(dt, dt1);
nestedScope.Dispose();
Assert.True(dt.IsDisposed);
}
示例5: RegistrationsMadeInLifetimeScopeCannotBeResolvedInItsParent
public void RegistrationsMadeInLifetimeScopeCannotBeResolvedInItsParent()
{
var container = new ContainerBuilder().Build();
container.BeginLifetimeScope(b => b.RegisterType<object>());
container.AssertNotRegistered<object>();
}
示例6: RegistrationsMadeInLifetimeScopeCanBeResolvedThere
public void RegistrationsMadeInLifetimeScopeCanBeResolvedThere()
{
var container = new ContainerBuilder().Build();
var ls = container.BeginLifetimeScope(b => b.RegisterType<object>());
ls.AssertRegistered<object>();
}
示例7: RegistrationsMadeInLifetimeScopeAreAdapted
public void RegistrationsMadeInLifetimeScopeAreAdapted()
{
var container = new ContainerBuilder().Build();
var ls = container.BeginLifetimeScope(b => b.RegisterType<object>());
ls.AssertRegistered<Func<object>>();
}