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

查看:124
本文介绍了使用依赖注入与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有pretty的酷基于上下文的事件的认识和处理功能,可以很可测试为code是分离的。

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的应用程序仍然是经常最好坚持使用这些直接在生产code。还有其他的框架之类的包装的基础平台;这些都是值得探讨,如果你有一个特定的目的(或者原型/实验),但对于支持的最佳水平,你通常是最好的标准组件坚持。

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.

这是一个很好的资源上的用户界面解决方案的工作时: http://www.androidpatterns.com/

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

专为DI:有一个 Spring框架为Android ,我已经与它玩,它看起来很有希望的。你已经提到Roboguice作为另一种选择这个。但是,为了避免性能和图书馆的开销,我仍然觉得最简单的方法是编写注册并注入在我自己的code依赖一个简单的基于反射的类。来这种方法,但我通常将注入code到一个单独的类似单从那里引用它。

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天全站免登陆