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


C# ContainerBuilder.BeginLifetimeScope方法代码示例

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

示例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");
 }
开发者ID:heran,项目名称:DReAM,代码行数:11,代码来源:AutofacTests.cs

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

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

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


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