当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.BeginLifetimeScope方法代码示例

本文整理汇总了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>());
 }
开发者ID:arronchen,项目名称:Autofac,代码行数:10,代码来源:CopyOnWriteRegistryTests.cs

示例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();
        }
开发者ID:ricardoshimoda,项目名称:Autofac,代码行数:12,代码来源:LifetimeScopeTests.cs

示例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);
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:12,代码来源:LifetimeScopeTests.cs

示例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);
        }
开发者ID:ricardoshimoda,项目名称:Autofac,代码行数:15,代码来源:LifetimeScopeTests.cs

示例5: RegistrationsMadeInLifetimeScopeCannotBeResolvedInItsParent

 public void RegistrationsMadeInLifetimeScopeCannotBeResolvedInItsParent()
 {
     var container = new ContainerBuilder().Build();
     container.BeginLifetimeScope(b => b.RegisterType<object>());
     container.AssertNotRegistered<object>();
 }
开发者ID:ricardoshimoda,项目名称:Autofac,代码行数:6,代码来源:LifetimeScopeTests.cs

示例6: RegistrationsMadeInLifetimeScopeCanBeResolvedThere

 public void RegistrationsMadeInLifetimeScopeCanBeResolvedThere()
 {
     var container = new ContainerBuilder().Build();
     var ls = container.BeginLifetimeScope(b => b.RegisterType<object>());
     ls.AssertRegistered<object>();
 }
开发者ID:ricardoshimoda,项目名称:Autofac,代码行数:6,代码来源:LifetimeScopeTests.cs

示例7: RegistrationsMadeInLifetimeScopeAreAdapted

 public void RegistrationsMadeInLifetimeScopeAreAdapted()
 {
     var container = new ContainerBuilder().Build();
     var ls = container.BeginLifetimeScope(b => b.RegisterType<object>());
     ls.AssertRegistered<Func<object>>();
 }
开发者ID:ricardoshimoda,项目名称:Autofac,代码行数:6,代码来源:LifetimeScopeTests.cs


注:本文中的ContainerBuilder.BeginLifetimeScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。