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


C# IContainerAdapter.CreateChildContainerAdapter方法代码示例

本文整理汇总了C#中IContainerAdapter.CreateChildContainerAdapter方法的典型用法代码示例。如果您正苦于以下问题:C# IContainerAdapter.CreateChildContainerAdapter方法的具体用法?C# IContainerAdapter.CreateChildContainerAdapter怎么用?C# IContainerAdapter.CreateChildContainerAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContainerAdapter的用法示例。


在下文中一共展示了IContainerAdapter.CreateChildContainerAdapter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MethodToBenchmark

        public override void MethodToBenchmark(IContainerAdapter container)
        {
            using (var childContainer = container.CreateChildContainerAdapter())
            {
                childContainer.Prepare();

                var scopedCombined = (ICombined1)childContainer.Resolve(typeof(ICombined1));
            }

            using (var childContainer = container.CreateChildContainerAdapter())
            {
                childContainer.Prepare();

                var scopedCombined = (ICombined2)childContainer.Resolve(typeof(ICombined2));
            }

            using (var childContainer = container.CreateChildContainerAdapter())
            {
                childContainer.Prepare();

                var scopedCombined = (ICombined3)childContainer.Resolve(typeof(ICombined3));
            }
        }
开发者ID:CodeDux,项目名称:IocPerformance,代码行数:23,代码来源:09_ChildContainer_Benchmark.cs

示例2: WarmUp


//.........这里部分代码省略.........
            if (complex == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(IComplex)));
            }

            if (container.SupportsPropertyInjection)
            {
                var propertyInjectionObject = (ComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));
                var propertyInjectionObject2 = (ComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));

                if (propertyInjectionObject == null || propertyInjectionObject2 == null)
                {
                    throw new Exception(
                         string.Format(
                         "Container {0} could not create type {1}",
                         container.PackageName,
                         typeof(IComplexPropertyObject)));
                }

                if (object.ReferenceEquals(propertyInjectionObject, propertyInjectionObject2) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceA, propertyInjectionObject2.ServiceA) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceB, propertyInjectionObject2.ServiceB) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceC, propertyInjectionObject2.ServiceC) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectA, propertyInjectionObject2.SubObjectA) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectB, propertyInjectionObject2.SubObjectB) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectC, propertyInjectionObject2.SubObjectC))
                {
                    throw new Exception(
                         string.Format(
                         "Container {0} could not correctly create type {1}",
                         container.PackageName,
                         typeof(IComplexPropertyObject)));
                }

                propertyInjectionObject.Verify(container.PackageName);
            }

            if (container.SupportGeneric)
            {
                var generic = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));

                if (generic == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportGeneric<int>)));
                }
            }

            if (container.SupportsMultiple)
            {
                var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));

                if (importMultiple == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportMultiple)));
                }
            }

            if (container.SupportsConditional)
            {
                var importObject = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));

                if (importObject == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject)));
                }

                var importObject2 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));

                if (importObject2 == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject2)));
                }
            }

            if (container.SupportsInterception)
            {
                var calculator = (ICalculator)container.ResolveProxy(typeof(ICalculator));
                calculator.Add(1, 2);
            }

            if (container.SupportsChildContainer)
            {
                using (var childContainer = container.CreateChildContainerAdapter())
                {
                    childContainer.Prepare();

                    ICombined scopedCombined = (ICombined)childContainer.Resolve(typeof(ICombined));

                    if (scopedCombined == null)
                    {
                        throw new Exception(string.Format("Child Container {0} could not create type {1}", container.PackageName, typeof(ICombined)));
                    }

                    if (!(scopedCombined is ScopedCombined))
                    {
                        throw new Exception(string.Format("Child Container {0} resolved type incorrectly should have been {1} but was {2}", container.PackageName, typeof(ICombined), scopedCombined.GetType()));
                    }
                }
            }
        }
开发者ID:huangyingwen,项目名称:IocPerformance,代码行数:101,代码来源:Program.cs

示例3: MeasureResolvePerformance

        private static void MeasureResolvePerformance(IContainerAdapter container, Result outputResult)
        {
            var singletonWatch = new Stopwatch();
            var transientWatch = new Stopwatch();
            var combinedWatch = new Stopwatch();
            var conditionsWatch = new Stopwatch();
            var genericWatch = new Stopwatch();
            var complexWatch = new Stopwatch();
            var multipleWatch = new Stopwatch();
            var propertyWatch = new Stopwatch();
            var childContainerWatch = new Stopwatch();

            for (int i = 0; i < LoopCount; i++)
            {
                singletonWatch.Start();
                var result1 = (ISingleton)container.Resolve(typeof(ISingleton));
                singletonWatch.Stop();

                transientWatch.Start();
                var result2 = (ITransient)container.Resolve(typeof(ITransient));
                transientWatch.Stop();

                combinedWatch.Start();
                var result3 = (ICombined)container.Resolve(typeof(ICombined));
                combinedWatch.Stop();

                complexWatch.Start();
                var complexResult = (IComplex)container.Resolve(typeof(IComplex));
                complexWatch.Stop();

                if (container.SupportsPropertyInjection)
                {
                    propertyWatch.Start();
                    var propertyInjectionResult = (IComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));
                    propertyWatch.Stop();
                }

                if (container.SupportsConditional)
                {
                    conditionsWatch.Start();
                    var result4 = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));
                    var result5 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));
                    conditionsWatch.Stop();
                }

                if (container.SupportGeneric)
                {
                    genericWatch.Start();
                    var genericResult = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));
                    genericWatch.Stop();
                }

                if (container.SupportsMultiple)
                {
                    multipleWatch.Start();
                    var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));
                    multipleWatch.Stop();
                }

                if (container.SupportsChildContainer && i < ChildContainerLoopCount)
                {
                    // Note I'm writing the test this way specifically because it matches the Per Request bootstrapper for Nance
                    // It's also a very common pattern used in MVC applications where a scope is created per request
                    childContainerWatch.Start();

                    using (var childContainer = container.CreateChildContainerAdapter())
                    {
                        childContainer.Prepare();

                        var scopedCombined = childContainer.Resolve(typeof(ICombined));
                    }

                    childContainerWatch.Stop();
                }
            }

            outputResult.SingletonTime = singletonWatch.ElapsedMilliseconds;
            outputResult.TransientTime = transientWatch.ElapsedMilliseconds;
            outputResult.CombinedTime = combinedWatch.ElapsedMilliseconds;
            outputResult.ComplexTime = complexWatch.ElapsedMilliseconds;

            if (container.SupportsPropertyInjection)
            {
                outputResult.PropertyInjectionTime = propertyWatch.ElapsedMilliseconds;
            }

            if (container.SupportGeneric)
            {
                outputResult.GenericTime = genericWatch.ElapsedMilliseconds;
            }

            if (container.SupportsMultiple)
            {
                outputResult.MultipleImport = multipleWatch.ElapsedMilliseconds;
            }

            if (container.SupportsConditional)
            {
                outputResult.ConditionalTime = conditionsWatch.ElapsedMilliseconds;
            }
//.........这里部分代码省略.........
开发者ID:huangyingwen,项目名称:IocPerformance,代码行数:101,代码来源:Program.cs


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