Tag: guice

Google Guice与PicoContainer进行dependency injection

我的团队正在研究dependency injection框架,并试图在使用Google-Guice和PicoContainer之间做出决定。 我们正在寻找我们的框架中的几件事情: 一个小的代码足迹 – 我的意思是一个小的代码足迹是我们不希望在我们的代码库中随处存在dependency injection代码。 如果我们需要重构道路,我们希望它尽可能简单。 性能 – 创build和注入对象时每个框架有多less开销? 易用性 – 是否有很大的学习曲线? 我们必须编写一些代码来获得简单的工作吗? 我们希望有尽可能less的configuration。 社区规模 – 较大的社区通常意味着项目将继续保持。 我们不想使用一个框架,并且必须修复我们自己的错误;)我们的任何问题都可以(希望)由框架的开发者/用户社区来回答。 这两个框架与所列标准的比较将不胜感激。 任何有助于比较两者的个人经验也是非常有帮助的。 免责声明:如果我提出一个与本次讨论无关的问题,我相当注意dependency injection,所以请原谅我的小心。

威胁中的约束

我刚开始玩Guice,我能想到的一个用例是,在一个testing中我只想重载一个绑定。 我想我想使用其余的生产级别的绑定,以确保一切安装正确,并避免重复。 所以想象我有以下模块 public class ProductionModule implements Module { public void configure(Binder binder) { binder.bind(InterfaceA.class).to(ConcreteA.class); binder.bind(InterfaceB.class).to(ConcreteB.class); binder.bind(InterfaceC.class).to(ConcreteC.class); } } 而在我的testing中,我只想重写InterfaceC,同时保持InterfaceA和InterfaceB的机智,所以我想要的东西是这样的: Module testModule = new Module() { public void configure(Binder binder) { binder.bind(InterfaceC.class).to(MockC.class); } }; Guice.createInjector(new ProductionModule(), testModule); 我也尝试了以下,没有运气: Module testModule = new ProductionModule() { public void configure(Binder binder) { super.configure(binder); binder.bind(InterfaceC.class).to(MockC.class); } }; Guice.createInjector(testModule); 有谁知道是否有可能做我想要的,或者我完全吠叫错误的树? […]