本文整理汇总了C#中WindsorContainer.ExecuteUnitOfWorkInIsolatedScope方法的典型用法代码示例。如果您正苦于以下问题:C# WindsorContainer.ExecuteUnitOfWorkInIsolatedScope方法的具体用法?C# WindsorContainer.ExecuteUnitOfWorkInIsolatedScope怎么用?C# WindsorContainer.ExecuteUnitOfWorkInIsolatedScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WindsorContainer
的用法示例。
在下文中一共展示了WindsorContainer.ExecuteUnitOfWorkInIsolatedScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
}
示例2: ClearEventstoreCache
protected void ClearEventstoreCache(WindsorContainer container)
{
if(EventStoreType == typeof(SqlServerEventStore))
{
container.ExecuteUnitOfWorkInIsolatedScope(() => ((SqlServerEventStore)container.Resolve<IEventStore>()).ClearCache());
}
}