本文整理汇总了C#中IContainerAdapter.ResolveProxy方法的典型用法代码示例。如果您正苦于以下问题:C# IContainerAdapter.ResolveProxy方法的具体用法?C# IContainerAdapter.ResolveProxy怎么用?C# IContainerAdapter.ResolveProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainerAdapter
的用法示例。
在下文中一共展示了IContainerAdapter.ResolveProxy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureProxy
private static long MeasureProxy(IContainerAdapter container)
{
var watch = Stopwatch.StartNew();
for (int i = 0; i < LoopCount; i++)
{
var result = (ICalculator)container.ResolveProxy(typeof(ICalculator));
// Call method because part of the time spent with a proxy is how long does it take to execute a proxied method
result.Add(5, 10);
}
return watch.ElapsedMilliseconds;
}
示例2: WarmUp
private static void WarmUp(IContainerAdapter container)
{
var interface1 = (ISingleton)container.Resolve(typeof(ISingleton));
if (interface1 == null)
{
throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ISingleton)));
}
var interface2 = (ITransient)container.Resolve(typeof(ITransient));
if (interface2 == null)
{
throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ITransient)));
}
var combined = (ICombined)container.Resolve(typeof(ICombined));
if (combined == null)
{
throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ICombined)));
}
var complex = (IComplex)container.Resolve(typeof(IComplex));
if (complex == null)
{
throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(IComplex)));
}
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);
}
}
示例3: 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()));
}
}
}
}
示例4: 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();
var interceptionTimeWatch = 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();
}
if(container.SupportsInterception)
{
interceptionTimeWatch.Start();
var result = (ICalculator)container.ResolveProxy(typeof(ICalculator));
// Call method because part of the time spent with a proxy is how long does it take to execute a proxied method
result.Add(5, 10);
interceptionTimeWatch.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;
//.........这里部分代码省略.........
示例5: WarmUp
private static void WarmUp(IContainerAdapter container)
{
var interface1 = (ISingleton)container.Resolve(typeof(ISingleton));
var interface2 = (ITransient)container.Resolve(typeof(ITransient));
var combined = (ICombined)container.Resolve(typeof(ICombined));
if (container.SupportsInterception)
{
var calculator = (ICalculator)container.ResolveProxy(typeof(ICalculator));
calculator.Add(1, 2);
}
}
示例6: MeasureProxy
private static long MeasureProxy(IContainerAdapter container)
{
var watch = Stopwatch.StartNew();
for (int i = 0; i < LoopCount; i++)
{
var result = (ICalculator)container.ResolveProxy(typeof(ICalculator));
}
return watch.ElapsedMilliseconds;
}
示例7: WarmUp
private static void WarmUp(IContainerAdapter container)
{
var interface1 = container.Resolve<ISingleton>();
var interface2 = container.Resolve<ITransient>();
var combined = container.Resolve<ISingleton>();
if (container.SupportsInterception)
{
var calculator = container.ResolveProxy<ICalculator>();
calculator.Add(1, 2);
}
}