Ninject and MonoDroid

删除回忆录丶 提交于 2020-01-14 03:20:50

问题


Anyone had any luck getting Ninject to work on MonoDroid? i've tried the 2.0 and 4.0 mono builds from their website and also tried the .net versions.

With the Mono builds i'm getting a MissingMethodException in the instantiation of my StandardKernel


回答1:


I am experimenting with Ninject on a combined WP7/Monotouch/Mono for Android project and Ninject works surprisingly good.

I used the latest sources, which contain a project file Ninject.WP7.csproj which seems to be outdated. It contains a lot of DefineConstants. I created new WP7/Monotouch/Mono for Android solutions with these constants and everything compiled and works!

Constants used:

SILVERLIGHT,SILVERLIGHT_40,NO_LCG,NO_ASSEMBLY_SCANNING,NO_WEB,NO_PARTIAL_TRUST,NO_SKIP_VISIBILITY,NO_EXCEPTION_SERIALIZATION,NO_DEBUG_SYMBOLS

not sure if they are all needed, but the SILVERLIGHT one is important because Monotouch/Mono for Android implement a large part of the Silverlight api.

Of course you cannot create Android Activities with Ninject. I use it mainly for constructor injection, to create .Net objects like a ViewManager, view models using a repository, etc., the usual things you do with dependency injection.




回答2:


I haven't tried to get Ninject working, but I'd be very surprised if it just worked out of the box. If there's a Silverlight build of Ninject you may have more luck with that, but there are no guarantees. The "best" way to get support for it in Mono for Android would be to build the code against the Mono for Android profile as a class library.

That said, there are other options out there for doing service location in your apps. I have a blog post up here that talks about using TinyIoC and Funq for service location.



来源:https://stackoverflow.com/questions/9992841/ninject-and-monodroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!