为什么根本没有用于通过Google Guice进行依赖项注入的配置文件? [英] Why there's no configuration file at all for dependency injection with Google Guice?

查看:71
本文介绍了为什么根本没有用于通过Google Guice进行依赖项注入的配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查 Google Guice作为DI框架,但我有点困惑:为什么根本没有配置文件?

I am checking out Google Guice as DI framework but I am a bit puzzled: why there's no configuration file at all?

我在,但仍不清楚如何在不使用以下命令的情况下设置组件角色(或需要使用开关的任何其他功能)

I found a partial explanation on this question but it is still not clear how I would be able to set my component roles (or any other thing I need to use a switch) without a config file.

感谢任何帮助!

推荐答案

配置是在代码中而不是配置文件中,这在许多情况下都是有效的决定。

The configuration is in the code instead of config files, which is a valid decision for many scenarios.

是的,这意味着如果您必须重建(可能只是模块)希望以其他方式发布应用程序-尽管当然您仍然可以从命令行参数,属性文件等中获取一些配置值。

Yes, it means that you have to rebuild (possibly just the modules) if you want to release a different way of plumbing your application - although of course you could still get some configuration values from command-line arguments, properties files etc if you want to.

如果您经常需要更改应用程序管道并且只想重新部署一个文件,则Guice可能不适合您。另一方面,如果您使用DI的主要原因是使您的代码更清晰,并且在生产中您始终真正使用相同的管道(或足够接近),那么Guice是一个不错的选择-您经常需要一些逻辑

If you regularly need to change your application plumbing and don't want to redeploy anything but a single file, Guice may not be for you. If on the other hand your main reason for using DI is to make your code clearer, and in production you'll always really use the same plumbing (or close enough) then Guice is a good option - there are often bits of logic you want to use when sorting out the plumbing anyway, and components which are generally hard to describe/construct declaratively.

不同的DI框架具有不同的优点和折衷-不论使用哪种方法,都必须使用它来清理管道。最适合您的应用。

Different DI frameworks have different benefits and trade-offs - use whichever one is most suitable for your application.

这篇关于为什么根本没有用于通过Google Guice进行依赖项注入的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆