Dose Unity AOP support web application?

Jan 31, 2013 at 11:47 AM
Edited Jan 31, 2013 at 11:51 AM
actually, i want to intercept events and methods calls in each page
Feb 1, 2013 at 4:57 AM
You can definitely use Unity in a web application.

However, if you want to hook into ASP.NET WebForms page and control lifetimes to perform interception then that is not supported (due to the nature of ASP.NET design). For new development, ASP.NET MVC would be the preferred approach since it allows easy use of dependency injection. See or How To Use Unity Container In ASP.NET MVC Framework for some information of this approach.

Randy Levy
Enterprise Library support engineer
Support How-to
Feb 1, 2013 at 10:28 AM
Thanks for your reply.

I also want to know if it is possible to intercept static methods in static class. I have seen your demo, but I find that creates a proxy for intercept instance method. So I would like to know if there are workarounds for interception without resolve an instance.

Feb 1, 2013 at 5:17 PM
Unity interception is based around proxy objects or derived classes so you can't intercept static methods. When the compiler sees a static method call it compiles that call directly into the IL so there is nothing that can be done at runtime to intercept the method call.

To handle static method interception you can use an IL weaving tool to inject the interception code into the IL. A popular (paid) product for this is PostSharp although I haven't used their product.

Randy Levy
Enterprise Library support engineer
Support How-to