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


C# WindsorContainer.BeginScope方法代码示例

本文整理汇总了C#中WindsorContainer.BeginScope方法的典型用法代码示例。如果您正苦于以下问题:C# WindsorContainer.BeginScope方法的具体用法?C# WindsorContainer.BeginScope怎么用?C# WindsorContainer.BeginScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WindsorContainer的用法示例。


在下文中一共展示了WindsorContainer.BeginScope方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUpContainerAndBeginScope

 public void SetUpContainerAndBeginScope()
 {
     Container = new WindsorContainer();
     Container.ConfigureWiringForTestsCallBeforeAllOtherWiring();
     Container.Register(
         Component.For<SynchronousBus>(),
         Component.For<EventsReplayer>(),
         Component.For<IWindsorContainer>().Instance(Container));
     new MessageHandlersRegister().RegisterMessageHandlersForTestingFromAssemblyContaining<MessageHandlersTestBase>(Container);
     Container.ConfigureWiringForTestsCallAfterAllOtherWiring();
     _scope = Container.BeginScope();
 }
开发者ID:RichieYang,项目名称:Composable.Monolithic,代码行数:12,代码来源:MessageHandlersTestBase.cs

示例2: ResolvingScopedComponents_ReturnsSameInstanceWithinTheScope

        public void ResolvingScopedComponents_ReturnsSameInstanceWithinTheScope()
        {
            IWindsorContainer container = new WindsorContainer();

            container.Register(
                Component.For<IRepository<Client>>().ImplementedBy<ClientRepository>().LifeStyle.Scoped());

            // IRepository<Client> can only be resolved within a scope
            using (container.BeginScope())
            {
                var instanceA = container.Resolve<IRepository<Client>>();
                var instanceB = container.Resolve<IRepository<Client>>();

                Assert.AreSame(instanceA, instanceB);
            }

            using (container.BeginScope())
            {
                var instanceC = container.Resolve<IRepository<Client>>();
            }

            container.Dispose();
        }
开发者ID:BravoAlpha,项目名称:ALapAroundIoCContainersDemo,代码行数:23,代码来源:Scoped.cs

示例3: Main

        static void Main(string[] args)
        {
            var container = new WindsorContainer();
            container.Install(FromAssembly.Named("Expenses"));

            using(container.BeginScope())
            {
                var iconsService = container.Resolve<BL.ExpenseIconService>();
                var context = container.Resolve<BL.UnitOfWorkContext>();
                foreach (var file in System.IO.Directory.GetFiles(@"..\..\Icons\", "*.png"))
                {
                    iconsService.CreateNewFromFile(Path.GetFileNameWithoutExtension(file), "image/png", File.ReadAllBytes(file));
                    context.SaveChanges();
                }
            }
        }
开发者ID:jechtom,项目名称:Expenses,代码行数:16,代码来源:Program.cs

示例4: SetupContainerAndScope

        public void SetupContainerAndScope()
        {
            Container = new WindsorContainer();
            Container.ConfigureWiringForTestsCallBeforeAllOtherWiring();
            Container.Install(
                FromAssembly.Containing<Domain.ContainerInstallers.AccountRepositoryInstaller>(),
                FromAssembly.Containing<Domain.Events.EventStore.ContainerInstallers.AccountManagementDomainEventStoreInstaller>(),
                FromAssembly.Containing<UI.QueryModels.ContainerInstallers.AccountManagementDocumentDbReaderInstaller>(),
                FromAssembly.Containing<UI.QueryModels.DocumentDB.Updaters.ContainerInstallers.AccountManagementQuerymodelsSessionInstaller>()
                );

            Container.Register(
                Component.For<IWindsorContainer>().Instance(Container),
                Component.For<IServiceBus>().ImplementedBy<SynchronousBus>()
                );

            Container.ConfigureWiringForTestsCallAfterAllOtherWiring();
            _scope = Container.BeginScope();
        }
开发者ID:RichieYang,项目名称:Composable.Monolithic,代码行数:19,代码来源:QueryModelsTestsBase.cs

示例5: UsingOnDistroyForScopedComponent_OnDestroyIsCalledScopeIsDisposed

        public void UsingOnDistroyForScopedComponent_OnDestroyIsCalledScopeIsDisposed()
        {
            IWindsorContainer container = new WindsorContainer();

            bool wasCalled = false;

            container.Register(
                Component.For<IRepository<Client>>()
                         .ImplementedBy<ClientRepository>()
                         .LifeStyle.Scoped()
                         .OnDestroy(component => wasCalled = true));

            using(container.BeginScope())
            {
                // ClientRepository also implements IDisposable,
                // Windsor will call Dispose when the component is released
                var repository = container.Resolve<IRepository<Client>>();
            }

            Assert.IsTrue(wasCalled);
        }
开发者ID:BravoAlpha,项目名称:ALapAroundIoCContainersDemo,代码行数:21,代码来源:DecommissionConcerns.cs

示例6: SetupContainerAndScope

        public void SetupContainerAndScope()
        {
            Container = new WindsorContainer();
            Container.ConfigureWiringForTestsCallBeforeAllOtherWiring();

            Container.Register(
                Component.For<IUtcTimeTimeSource, DummyTimeSource>().Instance(DummyTimeSource.Now).LifestyleSingleton(),
                Component.For<IWindsorContainer>().Instance(Container),
                Component.For<IServiceBus>().ImplementedBy<SynchronousBus>(),
                Component.For<IConnectionStringProvider>().Instance(new ConnectionStringConfigurationParameterProvider()).LifestyleSingleton()
                );

            Container.Install(
                FromAssembly.Containing<Domain.ContainerInstallers.AccountRepositoryInstaller>(),
                FromAssembly.Containing<Domain.Events.EventStore.ContainerInstallers.AccountManagementDomainEventStoreInstaller>(),
                FromAssembly.Containing<UI.QueryModels.ContainerInstallers.AccountManagementDocumentDbReaderInstaller>(),
                FromAssembly.Containing<UI.QueryModels.DocumentDB.Updaters.ContainerInstallers.AccountManagementQuerymodelsSessionInstaller>()
                );            

            Container.ConfigureWiringForTestsCallAfterAllOtherWiring();
            _scope = Container.BeginScope();
        }
开发者ID:mlidbom,项目名称:Composable.Monolithic,代码行数:22,代码来源:QueryModelsTestsBase.cs

示例7: using

        private static void RunScenarioWithEventStoreType
            (MigrationScenario scenario, Type eventStoreType, WindsorContainer container, IList<IEventMigration> migrations, int indexOfScenarioInBatch)
        {
            var startingMigrations = migrations.ToList();
            migrations.Clear();

            var timeSource = container.Resolve<DummyTimeSource>();

            IReadOnlyList<IAggregateRootEvent> eventsInStoreAtStart;
            using(container.BeginScope()) //Why is this needed? It fails without it but I do not understand why...
            {
                var eventStore = container.Resolve<IEventStore>();
                eventsInStoreAtStart = eventStore.ListAllEventsForTestingPurposesAbsolutelyNotUsableForARealEventStoreOfAnySize();
            }

            Console.WriteLine($"\n########Running Scenario {indexOfScenarioInBatch}");

            var original = TestAggregate.FromEvents(DummyTimeSource.Now, scenario.AggregateId, scenario.OriginalHistory).History.ToList();
            Console.WriteLine($"Original History: ");
            original.ForEach(e => Console.WriteLine($"      {e}"));
            Console.WriteLine();            

            var initialAggregate = TestAggregate.FromEvents(timeSource, scenario.AggregateId, scenario.OriginalHistory);
            var expected = TestAggregate.FromEvents(timeSource, scenario.AggregateId, scenario.ExpectedHistory).History.ToList();
            var expectedCompleteEventstoreStream = eventsInStoreAtStart.Concat(expected).ToList();

            Console.WriteLine($"Expected History: ");
            expected.ForEach(e => Console.WriteLine($"      {e}"));
            Console.WriteLine();

            var initialAggregate2 = TestAggregate.FromEvents(timeSource, scenario.AggregateId, scenario.OriginalHistory);

            timeSource.UtcNow += 1.Hours();//Bump clock to ensure that times will be be wrong unless the time from the original events are used..

            Console.WriteLine("Doing pure in memory ");            
            IReadOnlyList<IAggregateRootEvent> otherHistory = SingleAggregateInstanceEventStreamMutator.MutateCompleteAggregateHistory(
                scenario.Migrations,
                initialAggregate2.History.Cast<AggregateRootEvent>().ToList());

            AssertStreamsAreIdentical(expected, otherHistory, $"Direct call to SingleAggregateInstanceEventStreamMutator.MutateCompleteAggregateHistory");

            container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Save(initialAggregate));
            migrations.AddRange(startingMigrations);
            var migratedHistory = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Get<TestAggregate>(initialAggregate.Id)).History;            

            AssertStreamsAreIdentical(expected, migratedHistory, "Loaded un-cached aggregate");

            var migratedCachedHistory = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Get<TestAggregate>(initialAggregate.Id)).History;
            AssertStreamsAreIdentical(expected, migratedCachedHistory, "Loaded cached aggregate");


            Console.WriteLine("  Streaming all events in store");
            var streamedEvents = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStore>().ListAllEventsForTestingPurposesAbsolutelyNotUsableForARealEventStoreOfAnySize().ToList());
            
            AssertStreamsAreIdentical(expectedCompleteEventstoreStream, streamedEvents, "Streaming all events in store");
            
            Console.WriteLine("  Persisting migrations");
            using(container.BeginScope())
            {
                container.Resolve<IEventStore>().PersistMigrations();
            }

            migratedHistory = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Get<TestAggregate>(initialAggregate.Id)).History;            
            AssertStreamsAreIdentical(expected, migratedHistory, "Loaded aggregate");

            Console.WriteLine("Streaming all events in store");
            streamedEvents = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStore>().ListAllEventsForTestingPurposesAbsolutelyNotUsableForARealEventStoreOfAnySize().ToList());
            AssertStreamsAreIdentical( expectedCompleteEventstoreStream, streamedEvents, "Streaming all events in store");


            Console.WriteLine("  Disable all migrations so that none are used when reading from the event stores");
            migrations.Clear();

            migratedHistory = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Get<TestAggregate>(initialAggregate.Id)).History;
            AssertStreamsAreIdentical(expected, migratedHistory, "loaded aggregate");

            Console.WriteLine("Streaming all events in store");
            streamedEvents = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStore>().ListAllEventsForTestingPurposesAbsolutelyNotUsableForARealEventStoreOfAnySize().ToList());
            AssertStreamsAreIdentical(expectedCompleteEventstoreStream, streamedEvents, "Streaming all events in store");

            if(eventStoreType == typeof(SqlServerEventStore))
            {
                Console.WriteLine("Clearing sql server eventstore cache");
                container.ExecuteUnitOfWorkInIsolatedScope(() => ((SqlServerEventStore)container.Resolve<IEventStore>()).ClearCache());
                migratedHistory = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStoreSession>().Get<TestAggregate>(initialAggregate.Id)).History;
                AssertStreamsAreIdentical(expected, migratedHistory, "Loaded aggregate");

                Console.WriteLine("Streaming all events in store");
                streamedEvents = container.ExecuteUnitOfWorkInIsolatedScope(() => container.Resolve<IEventStore>().ListAllEventsForTestingPurposesAbsolutelyNotUsableForARealEventStoreOfAnySize().ToList());
                AssertStreamsAreIdentical(expectedCompleteEventstoreStream, streamedEvents, "Streaming all events in store");
            }

        }
开发者ID:mlidbom,项目名称:Composable.Monolithic,代码行数:93,代码来源:EventStreamMutatorTestsBase.cs


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