Binding, Blocking and Configuration
Learn binding, blocking, and configuration operations in Ratpack.
We'll cover the following...
Bindings
Bindings in Ratpack make objects available to the handlers. If you are familiar with Spring, Ratpack uses a Registry, which is similar to the application context in Spring. It can also be thought of as a simple map from class-types to instances. Ratpack-groovy uses Guice by default, although other direct-injection frameworks can be used (or none at all).
Instead of a formal plugin system, reusable functionality can be packaged as modules. You can create your own modules to properly decouple and organize your application into components. For example, you might want to create a MongoModule
or a JdbcModule
.
Alternatively, you could break your application into services. Either way, the registry is where you put them.
Anything in the registry can be automatically used in a handler and gets wired in by class-type from the registry. The following is an ...