简体   繁体   English

小脚印依赖注入java

[英]small footprint dependency injection java

I am looking for a very lightweight dependency injection framework for java. 我正在寻找一个非常轻量级的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. 沿着以下几行:接收Class es的java.util.List ,实例化它们,然后将所有对象自动连接到另一个。

I would recommend Spring , since this can provide a small footprint when using only the core packages. 我建议使用Spring ,因为在仅使用核心软件包时,这可以提供小的占用空间。

If you think Spring is overkill, then perhaps PicoContainer , or guice ? 如果你认为Spring太过分了,那么也许是PicoContainer或者guice

也许你应该看一下Google Guice: http//code.google.com/p/google-guice/

Silk DI is about 120K single jar file with no further runtime dependencies. Silk DI是大约120K单个jar文件,没有进一步的运行时依赖性。 It has a fluent binder interface like guice but is more flexible and allows to remove features you don't like. 它具有流畅的活页夹界面,如guice,但更灵活,可以删除你不喜欢的功能。 Eg Collection or List injection can be added in a one liner . 例如,可以在一个衬里中添加CollectionList注入。

I have been trying MentaContainer for less than a week now and I am satisfied by its clean and straightforward API. 我一直在尝试MentaContainer不到一个星期,我对它简洁明了的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. 它没有使用XML或Annotations进行设置,而是使用了一个流畅的API,几乎就像DSL一样让我觉得像天堂一样,因为我用它来构建一个支持IoC的小型Web容器。 It provides a THREAD scope for the components which fits perfectly for the REQUEST scope of the web container. 它为组件提供了一个THREAD范围,非常适合Web容器的REQUEST范围。 It is very lightweight so it may be what you need. 它非常轻巧,所以它可能是你需要的。

Definitely look into Guice. 绝对看看Guice。 Been using it for a year, and absolutely love it. 已经使用了一年,绝对喜欢它。

Take a look at dagger2, developped at google (forked of square's dagger1), for only 17kb jar. 看看dagger2,在谷歌(方形的匕首1分叉)开发,只有17kb的罐子。

  • Much less boilerplate than guice 比guice少得多的样板
  • compile time verification of injection (with explicit error message. That's something spring, guice does definitly not) 编译注射的时间验证(带有明确的错误信息。这是春天,guice确实没有)
  • generate Facotries, codes upon compile. 在编译时生成Facotries,代码。 Very powerfull 非常强大

dagger2 documentation dagger2 github dagger2 examples dagger2文档 dagger2 github dagger2示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM