本文整理汇总了C#中ServiceContainer.BeginScope方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer.BeginScope方法的具体用法?C# ServiceContainer.BeginScope怎么用?C# ServiceContainer.BeginScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContainer
的用法示例。
在下文中一共展示了ServiceContainer.BeginScope方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerLogicalCallContextTests
public PerLogicalCallContextTests()
{
container = new ServiceContainer();
container.Register<IFoo, Foo>(new PerScopeLifetime());
container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
scope = container.BeginScope();
}
示例2: GetInstance_Continuation_ThrowException
public void GetInstance_Continuation_ThrowException()
{
var container = new ServiceContainer();
container.Register<IBar, Bar>(new PerScopeLifetime());
container.Register<IAsyncFoo, AsyncFoo>();
using (container.BeginScope())
{
var instance = container.GetInstance<IAsyncFoo>();
Assert.Throws<AggregateException>(() => instance.GetBar().Wait());
}
}
示例3: GetInstance_Continuation_ReturnsInstance
public void GetInstance_Continuation_ReturnsInstance()
{
var container = new ServiceContainer();
container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
container.Register<IBar, Bar>(new PerScopeLifetime());
container.Register<IAsyncFoo, AsyncFoo>();
using (container.BeginScope())
{
var instance = container.GetInstance<IAsyncFoo>();
var bar = instance.GetBar().Result;
Assert.IsAssignableFrom(typeof(IBar), bar);
}
}
示例4: GetInstance_SameExecutionContext_InstancesAreSame
public void GetInstance_SameExecutionContext_InstancesAreSame()
{
var container = new ServiceContainer();
container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
container.Register<IBar, Bar>(new PerScopeLifetime());
container.Register<IAsyncFoo, AsyncFoo>();
using (container.BeginScope())
{
var firstBar = container.GetInstance<IBar>();
var instance = container.GetInstance<IAsyncFoo>();
var secondBar = instance.GetBar().Result;
Assert.Same(firstBar, secondBar);
}
}
示例5: Main
public static void Main(string[] args)
{
FluentCommandLineParser<Arguments> parser = ParserBuilder.Build();
var parserResult = parser.Parse(args);
if (!parserResult.HasErrors && !parserResult.EmptyArgs)
{
Arguments argument = parser.Object;
var container = new ServiceContainer();
container.RegisterFrom<CompositionRoot>();
using (var scope = container.BeginScope())
{
IFileParserManager fileParserManager = container.GetInstance<IFileParserManager>();
FileParserResult parseResult = fileParserManager.ParseFileAsync(argument.Path).Result;
}
}
}
示例6: Main
static void Main()
{
// Composition Root
// We're using a DI container now
var serviceContainer = new ServiceContainer();
serviceContainer.Register<IReader, ConsoleReader>();
serviceContainer.Register<IWriter>(f => new FileWriter(FilePath), "FileWriter", new PerRequestLifeTime());
serviceContainer.Register<IWriter, ConsoleWriter>("ConsoleWriter");
serviceContainer.Register<IWriter, CompositeWriter>();
serviceContainer.Register<CopyProcess>();
// Run the actual program
// Obtain the root object of the object graph that is necessary to run this program
using (serviceContainer.BeginScope())
{
var copyProcess = serviceContainer.GetInstance<CopyProcess>();
copyProcess.Execute();
} // Teardown happens here
}
示例7: EndCurrentScope_InScope_EndsScope
public void EndCurrentScope_InScope_EndsScope()
{
var container = new ServiceContainer();
ScopeManager manager = container.ScopeManagerProvider.GetScopeManager();
container.BeginScope();
container.EndCurrentScope();
Assert.Null(manager.CurrentScope);
}
示例8: LightInjecterScope
public LightInjecterScope(ServiceContainer container)
{
_container = container;
_container.BeginScope();
}