当前位置: 首页>>代码示例>>C#>>正文


C# ServiceContainer.BeginScope方法代码示例

本文整理汇总了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();
        }
开发者ID:rubenwe,项目名称:LightInject,代码行数:8,代码来源:PerLogicalCallContextTests.cs

示例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());                
            }
        }
开发者ID:vitamink,项目名称:LightInject,代码行数:12,代码来源:AsyncTests.cs

示例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);
            }
        }
开发者ID:vitamink,项目名称:LightInject,代码行数:14,代码来源:AsyncTests.cs

示例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);
            }
        }
开发者ID:vitamink,项目名称:LightInject,代码行数:15,代码来源:AsyncTests.cs

示例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;
         }
     }
 }
开发者ID:RamanBut-Husaim,项目名称:MA.DSP,代码行数:16,代码来源:Program.cs

示例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
        }
开发者ID:feO2x,项目名称:DependencyInversionPrinciple,代码行数:19,代码来源:Program.cs

示例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);
        }
开发者ID:vitamink,项目名称:LightInject,代码行数:10,代码来源:ScopeTests.cs

示例8: LightInjecterScope

 public LightInjecterScope(ServiceContainer container)
 {
     _container = container;
     
     _container.BeginScope();
 }
开发者ID:sbosell,项目名称:Hangfire.LightInject,代码行数:6,代码来源:LightInjectJobActivator.cs


注:本文中的ServiceContainer.BeginScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。