Unity Interceptor extension - mixin

Jul 27, 2009 at 8:44 PM
I have read this issue http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=1653
I thought it would be great if Unity through the extension of interceptors could implement interfaces on objects that do not.
For example:
public class MyType: ISerializable
            #region ISerializable Members

public void  GetObjectData(SerializationInfo info, StreamingContext context)
 	throw new NotImplementedException();


public interface OtherInterface
       void MethodNotImplementedForMyType;

public class OtherInterfaceHandler:ICallHandler{
#region ICallHandler Members

public IMethodReturn  Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 	//the call to GetNext () should not debolver implementation of the class since there is no

    //Execute the added functionality to my class
    return RegisterCallToOtherInterface();

public int  Order{get;set;}


public class Program

public static Main()

private static readonly IUnityContainer container = new UnityContainer().AddNewExtension<Interception>();

                .SetInterceptorFor(typeof(MyType), new TransparentProxyInterceptor())
                .AddPolicy(new Guid().ToString())
                .AddMatchingRule(new TypeMatchingRule(typeof(MyType)))
                .AddMatchingRule(new MemberNameMatchingRule("MethodNotImplemented*",true));


In this way, add functionality to my class implements a new interface without modifying my original code.

Is this possible? How hard would be implemented in Unity 2.0? You think something is important?


It is a feature that I would love to have available at Unity. I hope you will agree, and this post may be promoted as an issue and expect this feature in a new version.

Thank you very much!
I await your comments.
PS: Sorry for my bad English.


Jul 28, 2009 at 5:40 AM

I've wanted this feature ever since the first version of the Policy Injection Block (where the interception stuff started). It's on the backlog for Unity 2.0, but we'll see what happens - it's going to be very subtle, very complicated code to get right.


Jul 28, 2009 at 3:00 PM
I am aware of the delicacy of this functionality. If there is anything that can help, I will be happy.

Another thing I find interesting is to have a MatchRule by beanName, as springframework.

I am planning to build extensions of unity to support these features. If I can go up quickly as some progress