4

I'm working on a MonoDroid app, and there really isn't a good DI solution yet (at least that I know of).

I've gotten PostSharp to work on MonoDroid, and I'm using the Location Intercept aspect as a way to inject dependencies into fields/properties without using a service locator (outside of the aspect anyway).

Here's what I'm working with so far: https://github.com/mgroves/MonodroidStockPortfolio/blob/develop/MonoStockPortfolio/Framework/IoCAttribute.cs

It's rough, and definitely needs refactoring, but you get the idea from the basic structure. However, I'm not completely convinced that this approach is the best way. How would you go about using DI/IoC in a MonoDroid app, with or without PostSharp?

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
  • 1
    Isn't it service location what you mean instead of IoC? I don't get the I(nversion) of IoC combined with Aop – Paco Dec 20 '10 at 18:42
  • I use AOP to get hooks into the properties, and then I can use a service locator to resolve the dependency, but the service locator is *only* in the aspect, not scattered throughout the program – Matthew Groves Dec 21 '10 at 15:31

1 Answers1

7

It's more "classic container" rather than AOP, and MonoDroid isn't a platform I've tested it on (it's been tested on Mono, MonoTouch, Silverlight, Windows Mobile and WinPhone7 though), but TinyIoC should work if it fits the bill:

http://hg.grumpydev.com/tinyioc/wiki/Home

Steven Robbins
  • 26,441
  • 7
  • 76
  • 90
  • 2
    TinyIoC definitely works on MonoDroid, I've been using it lately. I'm actually working on a little framework of DI wrappers/helpers for MonoDroid and I'm currently using TinyIoC in it as well. – Greg Shackles Dec 20 '10 at 19:02