IBuliderContext AdditionalData

Feb 19, 2008 at 4:21 AM
WIth the latest BuilderStrategy refactoring, I lost the possibility to have contextual data between "before" and "after" the call down the chain:

Before I could do that:

public class MyStrategy : BuilderStrategy
  public override object BuildUp(IBuilderContext context, object buildKey, object existing)
    bool existedBefore = existing != null;
    existing = base.BuildUp(context, buildKey, existing);
   bool justBeenCreated = !existedBefore && (existing != null);
    if (justBeenCreated)
      //Raise some event that an object just been created.

Now with PreBuildUp and PostBuildUp, I lose this contextual capability.

If something like the following to the IBuilderContext, I could store this kind of contextual data for later on:

interface IBuilderContext
  IDictionary<string, object> TransientData { get; }

Of course one would say that given the IBuiderContext.Policies might become "writable" at some point, I could define a new transient policy to store this boolean. I think it would make things more complicated that they have to be.

Another solution could be to store contextual data into private instances but then you get concurrency issues that you didn't before with the old strategy buildup and that you don't get with the TransientData approach.
Feb 19, 2008 at 5:54 PM
After discussion, if you have transient policies, you can make TransientData part of a policy and register this policy as transient.