private static object ResolveArray <T>(IBuilderContext context) { IUnityContainer container = BuilderContext.NewBuildUp <IUnityContainer>(context); List <T> results = new List <T>(container.ResolveAll <T>()); return(results.ToArray()); }
/// <summary> /// Called during the chain of responsibility for a build operation. The /// PostBuildUp method is called when the chain has finished the PreBuildUp /// phase and executes in reverse order from the PreBuildUp calls. /// </summary> /// <param name="context">Context of the build operation.</param> public override void PostBuildUp(IBuilderContext context) { // If it's already been intercepted, don't do it again. if (context.Existing is IInterceptingProxy) { return; } Type originalType; if (!BuildKey.TryGetType(context.OriginalBuildKey, out originalType)) { return; } Type typeToIntercept; IInstanceInterceptionPolicy interceptionPolicy = FindInterceptorPolicy(context, out typeToIntercept); if (interceptionPolicy != null) { IInstanceInterceptor interceptor = interceptionPolicy.Interceptor; if (interceptor.CanIntercept(typeToIntercept)) { IUnityContainer container = BuilderContext.NewBuildUp <IUnityContainer>(context); InjectionPolicy[] policies = BuilderContext.NewBuildUp <InjectionPolicy[]>(context); PolicySet allPolicies = new PolicySet(policies); IInterceptingProxy proxy = interceptor.CreateProxy(typeToIntercept, context.Existing); bool hasHandlers = false; foreach (MethodImplementationInfo method in interceptor.GetInterceptableMethods(typeToIntercept, context.Existing.GetType())) { HandlerPipeline pipeline = new HandlerPipeline(allPolicies.GetHandlersFor(method, container)); if (pipeline.Count > 0) { proxy.SetPipeline(interceptor.MethodInfoForPipeline(method), pipeline); hasHandlers = true; } } if (hasHandlers) { context.Existing = proxy; } } } }
/// <summary> /// Called during the chain of responsibility for a build operation. The /// PostBuildUp method is called when the chain has finished the PreBuildUp /// phase and executes in reverse order from the PreBuildUp calls. /// </summary> /// <remarks>In this class, PostBuildUp checks to see if the object was proxyable, /// and if it was, wires up the handlers.</remarks> /// <param name="context">Context of the build operation.</param> public override void PostBuildUp(IBuilderContext context) { Guard.ArgumentNotNull(context, "context"); IInterceptingProxy proxy = context.Existing as IInterceptingProxy; if (proxy == null) { return; } ITypeInterceptionPolicy interceptionPolicy = GetInterceptionPolicy(context); Type typeToIntercept = BuildKey.GetType(context.BuildKey); PolicySet interceptionPolicies = new PolicySet(BuilderContext.NewBuildUp <InjectionPolicy[]>(context)); IUnityContainer currentContainer = BuilderContext.NewBuildUp <IUnityContainer>(context); foreach (MethodImplementationInfo item in interceptionPolicy.Interceptor.GetInterceptableMethods(typeToIntercept, typeToIntercept)) { HandlerPipeline pipeline = new HandlerPipeline( interceptionPolicies.GetHandlersFor(item, currentContainer)); proxy.SetPipeline(interceptionPolicy.Interceptor.MethodInfoForPipeline(item), pipeline); } }