IoC with AOP (PostSharp) in MonoDroid
-
11-10-2019 - |
문제
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?
해결책
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: