15

In Spring, if I want to have one set of objects for production, and another for local development/testing. I could use the @Profile annotation to designate the different classes, and switch between them by providing a system property when starting the app.

Is there anything like this in Guice, or do I need to manually check some property myself and load a different set of modules when bootstrapping my Injector?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Thorn G
  • 12,620
  • 2
  • 44
  • 56

1 Answers1

2

You'll need to identify the environment yourself, and choose which modules to apply in which environment, but you do have access to Modules.override to specifically override certain bindings without having to create a lot of module variants. Use it judiciously—it's very easy to get your modules tangled if you override many bindings or in unpredictable places.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251