/// <summary> /// Clears out any remembered IBuildPlan for this Instance /// </summary> public void ClearBuildPlan() { lock (_buildLock) { _plan = null; } }
/// <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))); } }
/// <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)); }
/// <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; } }
/// <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; } }
/// <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); }
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); }
/// <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 }; }
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); }
/// <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 }; }
public static T Build <T>(this IBuildPlan plan, IBuildSession session) where T : class { return(plan.Build(session, session.As <IContext>()).As <T>()); }
/// <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; }
public MockPlanBuilderPolicy(IBuildPlan builPlan) { _buildPlan = builPlan; }
/// <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)); } }