本文整理汇总了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();
}
示例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();
}
示例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();
}
}
}
示例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();
}
示例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);
}
示例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();
}
示例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");
}
}