在 Roboguice 中使用依赖注入? [英] Using Dependency Injection with Roboguice?

查看:25
本文介绍了在 Roboguice 中使用依赖注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个 Android 项目,我想知道有关构建 Android 应用程序的良好架构的任何建议.

I'm working on an Android project and I would like to know any recommendations about what's a good architecture to build an android application.

我想使用 Roboguice 进行依赖注入,并且我一直在阅读有关 MVVM 模式或 MVC 模式的信息(Android MVVM 设计模式示例).

I want to use dependency injection using Roboguice and I've been reading about MVVM pattern or MVC pattern (Android MVVM Design Pattern Examples).

我也知道 roboguice 有一个非常酷的基于上下文的事件的引发和处理功能,当代码解耦时,它可以非常易于测试.

Also I know that roboguice have a pretty cool Context-Based Event's raising and handling feature that could be very testable as the code is decoupled.

对工作设计模式有什么建议吗?您使用过或开发过的可测试且可扩展的架构?

Any recommendations on a working design pattern? a testable and scalable architecture you have worked with or developed?

推荐答案

Android 平台提供了一组通用的设计模式,并且与 Web 应用程序相比,您获得的硬件资源有限,因此通常最好坚持使用这些直接在生产代码中.还有其他框架可以包装"基本平台;如果您有特定目的(或者可能用于原型设计/实验),这些值得研究,但为了获得最佳支持,您通常最好坚持使用标准组件.

The Android platform provides a common set of design patterns, and with the limited hardware resources you get compared to Web-apps it is still often best to stick with using these directly in production code. There are other frameworks that sort of "wrap" the base platform; these are worth looking into if you have a specific purpose (or perhaps for prototyping/experimenting), but for the best level of support you are generally best sticking with the standard components.

这是处理 UI 解决方案的绝佳资源:http://www.androidpatterns.com/

This is a great resource when working on UI solutions: http://www.androidpatterns.com/

专门用于 DI:有一个 Android 的 Spring 框架,我玩过它,它看起来很有前途.您已经提到 Roboguice 作为另一种选择.但是,为了避免性能和库开销,我仍然发现最简单的方法是编写一个简单的基于反射的类,该类在我自己的代码中注册和注入依赖项.类似于这种方法,除了我通常将注入代码移到单独的单例中并引用从那里开始.

Specifically for DI: There is a Spring framework for Android, I've had a play with it and it looks quite promising. You've already mentioned Roboguice as another alternative to this. However, to avoid performance and library overhead, I still find the easiest approach is to write a simple reflection-based class that registers and injects dependencies within my own code. Similar to this approach, except I usually move the injection code into a separate singleton and reference it from there.

根据我的经验,大多数第三方产品目前还不够成熟,无法依赖,并且在基本平台提供的基础上并没有真正为您提供太多东西.然而,他们一直在进步,所以一定要不时尝试大牌.

In my experience most of the third-party offerings are not yet mature enough to rely on right now, and don't really give you much on top of what the base platform provides. They are constantly progressing, however, so be sure to experiment with the big names from time-to-time.

这篇关于在 Roboguice 中使用依赖注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆