How to intercept concrete class?

Topics: Policy Injection Application Block
Dec 23, 2011 at 3:32 PM

Hi ,

I have Business Object class. It is a concrete class and has no virtual methods. It refers Data access object via interface. I am able to setup interception for IDAO to concrete DAO classes. How to setup interception for Business Object?

Please provide me a sample and direct me to a sample  if this is possible.

Example of my code:

Service.cs: method1:

CodeBO  bo= Unity.resolve<CodeBO>();


CodeBO.cs Method1:

public class   CodeBo


 public void Method1()


IDAO dao=Unity.Resolve<IDAO>()




I am able to setup the interception for DAO as it has interface and concrete implementation... I am not able to do for business object.






Dec 23, 2011 at 9:42 PM

Unity supports 3 types of interceptors:

  • InterfaceInterceptor -- intercept a specific interface
  • TransparentProxyInterceptor -- intercept methods of objects that inherit from MarshalByRefObject
  • VirtualMethodInterceptor -- intercept virtual methods

See Unity Interception Techniques for a more detailed presentation.

So if your class does not implement an interface and has no virtual methods and does not inherit from MarshalByRefObject then it will not be eligible for
interception by Unity. 

From Scenarios for Interception:

There are some limitations on the type of objects that can be intercepted, depending on the interception mechanism you use. In general, objects must implement a known interface containing the methods and properties for which behaviors are required, inherit from the abstract base class MarshalByRefObject, or expose virtual methods that can be overridden in a derived class.

Hopefully, your business object can fit into one of those 3 categories.

Randy Levy
Enterprise Library support engineer