Android 和依赖注入

发布于 2024-08-18 17:58:11 字数 1437 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

游魂 2024-08-25 17:58:11

您似乎可以在 Android 上使用 Google Guice 2.0。您还可以查看 roboguice

编辑:

Spring 现在也可用于 Android

编辑:
Roboguice 现已弃用。您可以尝试 Toothpick,正如 Toothpick 背后的开发人员在评论中提到的。

It appears you can use Google Guice 2.0 with Android. You might also look into roboguice.

Edit:

Spring is also now available for Android

Edit:
Roboguice is now deprecated. You might try Toothpick as mentioned in the comments by the developer behind Toothpick.

在你怀里撒娇 2024-08-25 17:58:11

您可能还想考虑 Spring ME。虽然最初是用于 Java ME,但我也看到过有人将其用于 Android 的报告。这样做的好处是您拥有熟悉的编程模型 (Spring),而无需付出代价:Spring ME 的占用空间为 0k。

You might also want to consider Spring ME. Although originally intended for Java ME, I have seen reports from people using it for Android as well. The benefit would be that you have a familiar programming model (Spring) without the penalty: Spring ME has a 0k footprint.

长发绾君心 2024-08-25 17:58:11

如果你习惯在其他项目中使用Spring,你不会对Spring for Android(它只是一个支持Auth的REST库)、Spring ME(完全不同的工作流程和减少的功能集)或Tiny Spring(例如仅像Spring配置)。

不过,您可以尝试一下我的项目 RoboSpring。从描述来看:

RoboSpring 是 Spring 框架到 Android 平台的(真正的)端口。此外,它还为 RoboGuice 引入的功能提供初步支持,例如将视图引用注入活动等。 RoboSpring 基于 Spring 3.1.0 RELEASE 版本的核心、bean、context 和 aop 组件。它提供以下功能:

  • 使用 Spring 配置文件配置应用程序组件
    (XML)
  • 使用 Spring 应用程序上下文中的 bean 自动装配您的 Android 组件。
  • 将 Android 应用程序上下文注入到您的 Spring Beans 中。
  • 将视图注入到活动中。
  • …以及更多

https://github.com/dthommes/RoboSpring

If you are used to use Spring in other projects, you won't be very happy with Spring for Android (it's only a REST library with Auth support), Spring ME (completely different workflow and reduced featureset) or Tiny Spring (e.g. only Spring-like configuration).

You could however give my project RoboSpring a try. From the description:

RoboSpring is a (real) port of the Spring Framework to the Android platform. Additionally it offers preliminary support for functionality introduced by RoboGuice like injecting View references into Activities and more. RoboSpring is based on version 3.1.0 RELEASE of Spring's core, beans, context and aop components. It offers the following functionality:

  • Configure application components with a Spring configuration file
    (XML)
  • Autowire your Android components with beans from the Spring application context.
  • Inject the Android application context into your Spring Beans.
  • Inject views into Activities.
  • … and more

https://github.com/dthommes/RoboSpring

相思故 2024-08-25 17:58:11

还有一个适用于 Android 的新 Spring 项目:Tiny Spring。它解决了 XML 配置的基础问题,但并没有完成 Spring 所做的所有事情。

There is also a new Spring project for Android: Tiny Spring. It solves the very basics of XML configuration but doesn't do everything that Spring does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文