Binding constant values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Binding constant values

aalmiray
Administrator
Hello everyone,

I found myself playing with Google Guice today when encountered the need to bind a constant value such as

        bindConstant()
            .annotatedWith(named(GithubAPI.GITHUB_API_URL_KEY))
            .to("https://api.github.com");

This feature makes it easy to change constant values depending on the environment and I thought it would be great to have such feature in Griffon too, specially for testing. Well, I'm happy to report that Griffon already supports the feature! Albeit with a different syntax

        bind(String.class)
            .withClassifier(named(GithubAPI.GITHUB_API_URL_KEY))
            .toInstance("https://api.github.com");

Even better is that the syntax is supported since Griffon 2.0.0. If anyone needs this feature, now you know how to make it happen.

Cheers,
Andres