當前位置: 首頁>>代碼示例>>C#>>正文


C# Container.BeginLifetimeScope方法代碼示例

本文整理匯總了C#中SimpleInjector.Container.BeginLifetimeScope方法的典型用法代碼示例。如果您正苦於以下問題:C# Container.BeginLifetimeScope方法的具體用法?C# Container.BeginLifetimeScope怎麽用?C# Container.BeginLifetimeScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleInjector.Container的用法示例。


在下文中一共展示了Container.BeginLifetimeScope方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SimpleInjectorWebApiDependencyResolver

        private SimpleInjectorWebApiDependencyResolver(Container container, bool createScope)
        {
            _container = container;

            if (createScope)
            {
                _lifetimeScope = container.BeginLifetimeScope();
            }
        }
開發者ID:jsnmgpnty,項目名稱:Blogness2.0,代碼行數:9,代碼來源:SimpleInjectorWebApiDependencyResolver.cs

示例2: RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield

 public void RegistersDbContext_PropertyInjecting_GreenfieldDbInitializer_Transiently_WhenSettingIsGreenfield()
 {
     var container = new Container();
     container.ComposeRoot(new RootCompositionSettings { IsGreenfield = true, });
     using (container.BeginLifetimeScope())
     {
         var dbContext = container.GetInstance<EntityDbContext>();
         dbContext.Initializer.ShouldNotBeNull();
         dbContext.Initializer.ShouldBeType<GreenfieldDbInitializer>();
     }
 }
開發者ID:phobos04,項目名稱:tripod,代碼行數:11,代碼來源:CompositionRootTests.cs

示例3: RegisterAzureAlone_GetIUnitOfWorkInstance_ThrowsActivationException

        public void RegisterAzureAlone_GetIUnitOfWorkInstance_ThrowsActivationException()
        {
            using (var container = new Container())
            {
                var adapter = BuildNewAdapter(container);

                adapter.RegisterAzureBlob<FakeBlobContext>();
                adapter.RegisterAzureQueue<FakeQueueContext>();
                adapter.RegisterAzureTable<FakeTableContext>();

                using (container.BeginLifetimeScope())
                {
                    // ReSharper disable once AccessToDisposedClosure
                    Assert.Throws<ActivationException>(() => container.GetInstance<IUnitOfWork>());
                }
            }
        }
開發者ID:LeonardoLimaDaSilva,項目名稱:Abstractor,代碼行數:17,代碼來源:CompositionRootTests.cs

示例4: RegisterEntityFrameworkAlone_IUnitOfWorkShouldBeEntityFrameworkUnitOfWork

        public void RegisterEntityFrameworkAlone_IUnitOfWorkShouldBeEntityFrameworkUnitOfWork()
        {
            using (var container = new Container())
            {
                var adapter = BuildNewAdapter(container);

                adapter.RegisterEntityFramework<FakeEfContext>();

                using (container.BeginLifetimeScope())
                {
                    var uow = container.GetInstance<IUnitOfWork>();
                    uow.GetType()
                        .FullName.Should()
                        .Be("Abstractor.Cqrs.EntityFramework.Persistence.EntityFrameworkUnitOfWork");

                    uow.Commit();
                    uow.Clear();
                }
            }
        }
開發者ID:LeonardoLimaDaSilva,項目名稱:Abstractor,代碼行數:20,代碼來源:CompositionRootTests.cs

示例5: RegisterEntityFrameworkAzureAndUnitOfWork_IUnitOfWorkShouldBeUnitOfWork

        public void RegisterEntityFrameworkAzureAndUnitOfWork_IUnitOfWorkShouldBeUnitOfWork()
        {
            using (var container = new Container())
            {
                var adapter = BuildNewAdapter(container);

                adapter.RegisterEntityFramework<FakeEfContext>();
                adapter.RegisterAzureBlob<FakeBlobContext>();
                adapter.RegisterAzureQueue<FakeQueueContext>();
                adapter.RegisterAzureTable<FakeTableContext>();
                adapter.RegisterUnitOfWork();

                using (container.BeginLifetimeScope())
                {
                    var uow = container.GetInstance<IUnitOfWork>();
                    uow.GetType().FullName.Should().Be("Abstractor.Cqrs.UnitOfWork.Persistence.UnitOfWork");

                    uow.Commit();
                    uow.Clear();
                }
            }
        }
開發者ID:LeonardoLimaDaSilva,項目名稱:Abstractor,代碼行數:22,代碼來源:CompositionRootTests.cs

示例6: RegisterUnitOfWorkAndEntityFramework_ThrowsActivationException

        public void RegisterUnitOfWorkAndEntityFramework_ThrowsActivationException()
        {
            using (var container = new Container())
            {
                var adapter = BuildNewAdapter(container);

                adapter.RegisterUnitOfWork();
                adapter.RegisterEntityFramework<FakeEfContext>();

                using (container.BeginLifetimeScope())
                {
                    // ReSharper disable once AccessToDisposedClosure
                    Assert.Throws<ActivationException>(() => container.GetInstance<IUnitOfWork>());
                }
            }
        }
開發者ID:LeonardoLimaDaSilva,項目名稱:Abstractor,代碼行數:16,代碼來源:CompositionRootTests.cs

示例7: RegisterEntityFrameworkWithDependencyInjection_ShouldResolveWithoutErrors

        public void RegisterEntityFrameworkWithDependencyInjection_ShouldResolveWithoutErrors()
        {
            using (var container = new Container())
            {
                var adapter = BuildNewAdapter(container);

                adapter.RegisterEntityFramework<FakeEfContextWithDependencyInjection>();

                using (container.BeginLifetimeScope())
                {
                    var logger = (FakeLogger)container.GetInstance<ILogger>();
                    var uow = container.GetInstance<IUnitOfWork>();
                    uow.GetType()
                        .FullName.Should()
                        .Be("Abstractor.Cqrs.EntityFramework.Persistence.EntityFrameworkUnitOfWork");

                    uow.Commit();
                    uow.Clear();

                    logger.Message.Should().Be("Changes saved.");
                }
            }
        }
開發者ID:LeonardoLimaDaSilva,項目名稱:Abstractor,代碼行數:23,代碼來源:CompositionRootTests.cs


注:本文中的SimpleInjector.Container.BeginLifetimeScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。