AOP with MonoTouch [closed]
Asked Answered
B

3

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.

Briseno answered 4/4, 2012 at 5:49 Comment(0)
O
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/

Osmose answered 4/4, 2012 at 13:14 Comment(1)
That's because you could use the Silverlight DLL; I (think) cannot reference this DLL in MonoDevelop in a Monotouch project.Briseno
C
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.

Cinnamon answered 4/4, 2012 at 13:24 Comment(0)
U
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).

Uredo answered 4/5, 2014 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.