Proxy as a container for additional properties.

Topics: Development Team Discussion, User Discussion
Aug 16, 2007 at 1:58 PM
I am looking for a way to store per target-instance additional data. Instead of going on the static-dictionary-weakref path, I thought the proxy would be a nicer container.

What if InterceptingRealProxy and any other proxy for that matter (ILEmit, ...) would implement the following:

public interface IPropertyContainer
IDictionary<object, object> Properties { get; }

We could then retrieve the RealProxy from a target-instance and cast it to IPropertyContainer.
Aug 16, 2007 at 4:27 PM
Good idea, but I'm not sure it is the right way to expose the functionality.

The real proxy is an implementation detail (the proxy is not used in some implementations of the weaver, for instance PostSharp4EntLib), so we cannot have the contract depending on it. Would it be possible to have the same functionality without relying on the proxy? I think the dictionary should be exposed on the object giving the "context" of the invocation (IMethodInvocation).

That being said, even if one would decide that the feature should be exposed on IPropertyContainer, I would find a way to implement it using PostSharp4EntLib :-).
Aug 16, 2007 at 5:43 PM
I definitely agree the context (Properties Container) should be exposed on the IMethodInvocation. Actually it's already there (IMethodInvocation.InvocationContext)

However, if I try to rephrase, I am more looking for a place to store data that would get pushed into the InvocationContext on every call. Some sort of "Constant Context".

So maybe InterceptingRealProxy could keep an IDictionary called ConstantContext as a private member and push it into every InvocationContext on every call. This way, you get By-instance context.

I'll try to come up with something as well ;)
Aug 16, 2007 at 6:05 PM
I understood you want an instance-bound context, i.e. you want to be able to "add fields" to aspected objects.

In my understanding, it is possible to store this dictionary of "tags" to InterceptingRealProxy. And in the PostSharp4EntLib implementation, I would use the "Instance Tag" functionality of PostSharp Laos (which actually adds a field to the type).