google / google/guice

@Development and @Production for stage

Open
#1,008 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

When I want to have different configuration settings for development and for production I use the currentStage()

``` java
class MyModule extends AbstractModule {
@Override
protected void configure() {
if (currentStage() == Stage.DEVELOPMENT) {
bind(DataSource.class).toProvider(DevDataSourceProvider.class).in(Singleton.class);
} else {
bind(DataSource.class).toProvider(DataSourceProvider.class).in(Singleton.class);
}
}
}
```

But sometimes my providers are so simple that I write it directly on the module. Here I wish there was an annotation `@Development` to represent the `DEVELOPMENT` stage and a `@Production` for the `PRODUCTION` stage

``` java
class MyModule extends AbstractModule {
@Override
protected void configure() {
}

@Development
@Provides
DataSource provideDevDataSource() {}

@Production
@Provides
DataSource provideDataSource() {}
}
```

Or something like this

``` java
@Provides(Stage.DEVELOPMENT)
DataSource provideDevDataSource() {}

@Provides(Stage.PRODUCTION)
DataSource provideDataSource() {}
```

Thank you.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.