Why there's no configuration file at all for dependency injection with Google Guice?

后端 未结 6 2392
生来不讨喜
生来不讨喜 2021-02-19 23:51

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 i

6条回答
  •  天涯浪人
    2021-02-20 00:52

    Most of the DI configuration will be the same from one deployment to another, so they can very well be configured using code, which makes Guice's configuration very terse and you get the benefits of compile time type checking, refactoring tools, code navigation etc.

    For those few things that change from deployment to another, such as the database username and password configuration, you can write the needed code yourself. Write code which reads the configuration file (maybe a properties file), parses the parameters, and binds them in your Guice modules so that your application gets access to them. The code that is needed for doing that won't take many lines of code.

提交回复
热议问题