AOP with MonoTouch

Go To StackoverFlow.com

5

I was wondering if there is any support for AOP (Aspect Oriented Programming) together with MonoTouch (and thereby with MonoDevelop).

So far I was not able to find any tools that support MonoDevelop. As far as I can see, tools like PostSharp are not supported.

2012-04-04 05:49
by Stefan de Vogelaere


3

I was able to get PostSharp working on Mono for Android (with Visual Studio). I've not used MonoTouch, but you might give it a try anyway: http://mgroves.com/monodroid-with-postsharp/

2012-04-04 13:14
by Matthew Groves
That's because you could use the Silverlight DLL; I (think) cannot reference this DLL in MonoDevelop in a Monotouch project - Stefan de Vogelaere 2012-04-05 13:56


2

Tools that do not depend on dynamic code generation should work with MonoTouch. IIRC PostSharp is such a tool - i.e. it modify the IL to get results.

The reason it's more restrictive for MonoTouch (than other .NET platforms, including Mono for Android) is that iOS does not allow code generation so we cannot JIT on the devices. This means all MonoTouch application must be compiled AOT (ahead of time).

Note the fact that a tool could work does not meant it will work. E.g. the tools must be able to be executed on OSX and you need to integrate this into the build (after C# compilation but before AOT compilation). The later might require you to use scripts/Makefile to build your project.

2012-04-04 13:24
by poupou


2

I've recently created a Fody addin called StaticProxy.Fody which compile-time weaves interception code into a class and can also auto-implement interfaces. This is more or less what for example castle dynamic proxy "interface proxy without target" and "interface proxy with target" and "class proxy" provide. Note however, that it is limited in that you need to mark interfaces / classes which should be woven by a [StaticProxy] attribute. Thus, you can only intercept types where you can add this (==> source under your control).

Also, because it adds a constructor argument, the use of a dependency injection container is basically mandatory (it breaks "new Foo(..)" calls). I've already created extensions for ninject and unity:

nuget packages are available and i would very much welcome it if someone could test MonoTouch / MonoDroid integration. I fear that i'm currently not correctly creating the nuget package.

I'm also planning to add auto-factory implementations (like ninject's ".ToFactory()" binding).

2014-05-04 16:14
by BatteryBackupUnit
Ads