小足迹依赖注入java
我正在寻找一个非常轻量级的java依赖注入框架。 具有尽可能少的依赖性和最少的功能。
只需遵循以下几行:接收 Class
的 java.util.List
,实例化它们,然后将所有对象自动连接到另一个对象中。
I am looking for a very lightweight dependency injection framework for java.
With minimum possible dependencies and minimum features.
Just something along the following lines: receive a java.util.List
of Class
es, instantiate them and just auto-wire all the objects one into the other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我会推荐 Spring,因为当仅使用核心包时,它可以提供较小的占用空间。
如果您认为 Spring 太过分了,那么也许可以使用 PicoContainer 或 guice?
I would recommend Spring, since this can provide a small footprint when using only the core packages.
If you think Spring is overkill, then perhaps PicoContainer, or guice?
也许你应该看看 Google Guice:http://code.google.com/p/谷歌-guice/
Maybe you should have a look at Google Guice: http://code.google.com/p/google-guice/
Silk DI 是大约
120K
单个 jar 文件,没有进一步的运行时依赖项。它有一个像 guice 一样流畅的活页夹界面,但更灵活,并且允许删除您不喜欢的功能。例如,Collection
或List
注入可以添加到一个衬垫中。Silk DI is about
120K
single jar file with no further runtime dependencies. It has a fluent binder interface like guice but is more flexible and allows to remove features you don't like. E.g.Collection
orList
injection can be added in a one liner.我已经尝试 MentaContainer 不到一周了,我对其干净、简单的 API 感到满意。它没有使用 XML 或注释进行设置,而是使用流畅的 API,几乎像 DSL,这对我来说就像天堂一样,因为我使用它来构建一个支持 IoC 的小型 Web 容器。它为组件提供了一个 THREAD 范围,非常适合 Web 容器的 REQUEST 范围。它非常轻,所以它可能正是您所需要的。
I have been trying MentaContainer for less than a week now and I am satisfied by its clean and straightforward API. Instead of using XML or Annotations for the setup it uses a fluent API almost like a DSL which for me felt like like heaven because I am using it to build a small web container with IoC support. It provides a THREAD scope for the components which fits perfectly for the REQUEST scope of the web container. It is very lightweight so it may be what you need.
看一下 dagger2,它是由 google 开发的(由 square 的 dagger1 分叉),jar 大小只有 17kb。
dagger2 文档
dagger2 github
dagger2 示例
Take a look at dagger2, developped at google (forked of square's dagger1), for only 17kb jar.
dagger2 documentation
dagger2 github
dagger2 examples
一定要调查吉斯。使用它已经一年了,非常喜欢它。
Definitely look into Guice. Been using it for a year, and absolutely love it.
查看 ActiveJ Inject。
它是一个轻量级的依赖注入库。它针对性能进行了优化,并且没有第三方依赖项。
它比 Spring DI 或 Guice 快得多,而且更轻。 此处查看基准测试
Take a look at ActiveJ Inject.
It is a lightweight dependency injection library. It is optimized for performance and has no third-party dependencies.
It is much faster than Spring DI or Guice and it is much lighter. Check the benchmarks here