예제 #1
0
 /// <summary>
 /// Clears out any remembered IBuildPlan for this Instance
 /// </summary>
 public void ClearBuildPlan()
 {
     lock (_buildLock)
     {
         _plan = null;
     }
 }
예제 #2
0
 /// <summary>
 /// Resolves the IBuildPlan for this Instance.  The result is remembered
 /// for subsequent requests
 /// </summary>
 /// <param name="pluginType"></param>
 /// <param name="policies"></param>
 /// <returns></returns>
 public IBuildPlan ResolveBuildPlan(Type pluginType, Policies policies)
 {
     lock (_buildLock)
     {
         return(_plan ?? (_plan = buildPlan(pluginType, policies)));
     }
 }
예제 #3
0
        /// <summary>
        /// Implementation of <see cref="IBuilderStrategy.BuildUp"/>.
        /// </summary>
        /// <param name="context">The build context.</param>
        /// <param name="typeToBuild">The type of the object being built.</param>
        /// <param name="existing">The existing instance of the object.</param>
        /// <param name="idToBuild">The ID of the object being built.</param>
        /// <returns>The built object.</returns>
        public override object BuildUp(
            IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            IBuildPlan buildPlan = GetPlanFromContext(context, typeToBuild, idToBuild);

            existing = buildPlan.BuildUp(context, typeToBuild, existing, idToBuild);
            return(base.BuildUp(context, typeToBuild, existing, idToBuild));
        }
예제 #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="typeToBuild"></param>
 /// <param name="plan"></param>
 public void Set(Type typeToBuild, IBuildPlan plan)
 {
     lock (lockObject)
     {
         Dictionary<Type, IBuildPlan> newPlans =
             new Dictionary<Type, IBuildPlan>(buildPlans);
         newPlans[typeToBuild] = plan;
         buildPlans = newPlans;
     }
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="typeToBuild"></param>
 /// <param name="plan"></param>
 public void Set(Type typeToBuild, IBuildPlan plan)
 {
     lock (lockObject)
     {
         Dictionary <Type, IBuildPlan> newPlans =
             new Dictionary <Type, IBuildPlan>(buildPlans);
         newPlans[typeToBuild] = plan;
         buildPlans            = newPlans;
     }
 }
예제 #6
0
        /// <summary>
        /// Get instance for the specified buil plan
        /// </summary>
        /// <param name="bp">Build plan describing how to create and store the object</param>
        /// <param name="requestedService">Service to build.</param>
        /// <returns>Created instance (throw exception if it can't be built).</returns>
        protected virtual object GetInstance(IBuildPlan bp, Type requestedService)
        {
            if (requestedService == null)
            {
                throw new ArgumentNullException("requestedService");
            }
            var    context = new CreateContext(this, RootStorage, ChildStorage, requestedService);
            object instance;

            bp.GetInstance(context, out instance);
            return(instance);
        }
예제 #7
0
        private static IBuildPlan GetPlanFromContext(IBuilderContext context, Type typeToBuild, string idToBuild)
        {
            IBuildPlanPolicy planPolicy = GetPlanPolicyFromContext(context, typeToBuild, idToBuild);
            IBuildPlan       plan       = planPolicy.Get(typeToBuild);

            if (plan == null)
            {
                IPlanBuilderPolicy builderPolicy = GetPlanBuilderFromContext(context, typeToBuild, idToBuild);
                plan = builderPolicy.CreatePlan(typeToBuild, idToBuild);
                planPolicy.Set(typeToBuild, plan);
            }
            return(plan);
        }
예제 #8
0
        /// <summary>
        /// Resolves the IBuildPlan for this Instance.  The result is remembered
        /// for subsequent requests
        /// </summary>
        /// <param name="pluginType"></param>
        /// <param name="policies"></param>
        /// <returns></returns>
        public IBuildPlan ResolveBuildPlan(Type pluginType, Policies policies)
        {
            if (_plan == null)
            {
                lock (_buildLock)
                {
                    if (_plan == null)
                    {
                        _plan = buildPlan(pluginType, policies);
                    }
                }
            }

            return(_plan);
        }
        /// <summary>
        /// Add another constructor parameter plan
        /// </summary>
        /// <param name="index">Index of the constructor parameter</param>
        /// <param name="bp">Plan used to construct the parameter</param>
        public void AddConstructorPlan(int index, IBuildPlan bp)
        {
            if (bp == null)
            {
                throw new ArgumentNullException("bp");
            }
            if (index < 0 || index >= Constructor.GetParameters().Length)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            _parameters[index] = new ConstructorParameter
            {
                BuildPlan   = bp,
                ServiceType = Constructor.GetParameters()[index].ParameterType
            };
        }
예제 #10
0
        object ICreateCallback.InstanceCreated(CreateContext context, IBuildPlan buildPlan, object instance)
        {
            if (_decorators.Count == 0)
            {
                return(instance);
            }

            var ctx = new DecoratorContext(buildPlan.Services, buildPlan.Lifetime)
            {
                Instance = instance, RequestedService = context.RequestedService
            };

            foreach (var decorator in _decorators)
            {
                decorator.Decorate(ctx);
            }

            return(ctx.Instance);
        }
예제 #11
0
        /// <summary>
        /// Add another constructor parameter plan
        /// </summary>
        /// <param name="index">Index of the constructor parameter</param>
        /// <param name="bp">Plan used to construct the parameter</param>
        public void AddConstructorPlan(int index, IBuildPlan bp)
        {
            if (bp == null) throw new ArgumentNullException("bp");
            if (index < 0 || index >= Constructor.GetParameters().Length)
                throw new ArgumentOutOfRangeException("index");

            _parameters[index] = new ConstructorParameter
                                     {
                                         BuildPlan = bp,
                                         ServiceType = Constructor.GetParameters()[index].ParameterType
                                     };
        }
예제 #12
0
 public static T Build <T>(this IBuildPlan plan, IBuildSession session) where T : class
 {
     return(plan.Build(session, session.As <IContext>()).As <T>());
 }
예제 #13
0
        /// <summary>
        /// Resolves the IBuildPlan for this Instance.  The result is remembered
        /// for subsequent requests
        /// </summary>
        /// <param name="pluginType"></param>
        /// <param name="policies"></param>
        /// <returns></returns>
        public IBuildPlan ResolveBuildPlan(Type pluginType, Policies policies)
        {
            if (_plan == null)
            {
                lock (_buildLock)
                {
                    if (_plan == null)
                    {
                        _plan = buildPlan(pluginType, policies);
                    }
                }
            }

            return _plan;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompositeBuildPlan"/> class.
 /// </summary>
 /// <param name="serviceType">Should be type of <c><![CDATA[IEnumerable<TheType>]]></c></param>
 /// <param name="buildPlans">The build plans.</param>
 public CompositeBuildPlan(Type serviceType, IBuildPlan[] buildPlans)
 {
     _serviceType = serviceType;
     _buildPlans = buildPlans;
 }
예제 #15
0
 public MockPlanBuilderPolicy(IBuildPlan builPlan)
 {
     _buildPlan = builPlan;
 }
예제 #16
0
 /// <summary>
 /// Resolves the IBuildPlan for this Instance.  The result is remembered
 /// for subsequent requests
 /// </summary>
 /// <param name="pluginType"></param>
 /// <param name="policies"></param>
 /// <returns></returns>
 public IBuildPlan ResolveBuildPlan(Type pluginType, Policies policies)
 {
     lock (_buildLock)
     {
         return _plan ?? (_plan = buildPlan(pluginType, policies));
     }
 }
예제 #17
0
 /// <summary>
 /// Clears out any remembered IBuildPlan for this Instance
 /// </summary>
 public void ClearBuildPlan()
 {
     lock (_buildLock)
     {
         _plan = null;
     }
 }
 public MockPlanBuilderPolicy(IBuildPlan builPlan)
 {
     _buildPlan = builPlan;
 }