Martin
Martin

Reputation: 24308

Unity: Interception (AOP) intercepting Properties? and also intercepting methods on a form (winform)?

i am very interested in finding out if its possible to intercept Properties as well as Methods? I found a great example and seems to support intercepting Methods, would it also be possible to intercept Properties and what about events??

I would like to write a AOP logging system for my app.

here is the example: http://codetheorist.com/2011/04/interception-made-easy/

I gave it a try and managed to get it to work on a class library,

what if i would like to get it to work on WinForms? I need to also resolve the Form from the container, a form in reality is a class but i couldn't get it to work.

Anyone have any ideas, or has already done it?

I did notice Aurum which is framework on top of Unity but i think i would prefer to use the Unity extensions if at all possible.

EDIT

This is what i tried for my winforms.... but it didn't work, its in program.cs

var form = UnityContainer.Container.Resolve<frmMain>();

///Application.Run(new frmMain());  // OLD

Application.Run(form);  // new using the resolved from unity.. It resolves it and i registered it ... 

Upvotes: 2

Views: 896

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233150

A property is just a method with some additional metadata, so if the property is virtual or part of an interface it can be intercepted - just like any other virtual method.

Upvotes: 2

Related Questions