本文整理匯總了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.");
}
}
}