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