KnowForge/Google Guice
Best Practices
JavaGoogleGuice
qianmoQqianmoQ78 个章节
目录
  • User's Guide
  • Common Guice Errors
  • Best Practices
  • Frequently Asked Questions
  • Integration
  • Extensions
  • Internals
  • Releases
  • Community
Powered by KnowForge

Best Practices

qianmoQqianmoQ· 更新于 2026-09-23· 阅读 4 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Guice Best Practices

  • Minimize mutability
  • Inject only direct dependencies
  • Use the Injector as little as possible (preferably only once)
  • Avoid cyclic dependencies
  • Avoid static state
  • Use @Nullable
  • Modules should be fast and side-effect free
  • Be careful about I/O in Providers
  • Avoid conditional logic in modules
  • Keep constructors as hidden as possible
  • Avoid binding Closable resources
  • Prefer @Provides methods over the binding DSL
  • Avoid calling @Provides methods and @Inject constructors directly
  • Don't reuse binding annotations (aka @Qualifiers)
  • Organize modules by feature, not by class type
  • Document the public bindings provided by modules

评论

登录后参与评论

正在加载评论…
上一篇Common Guice ErrorsqianmoQ
下一篇Frequently Asked QuestionsqianmoQ

本章目录

本章暂无目录

阅读设置

qianmoQ
查看作者主页