Initializing data with eager binding in play


Knoldus

I just came across a scenario where I had not to choose Play GlobalSettings to execute some tasks on start up of the application, as it is being deprecated in Play 2.5. So as the alternative what we can do to make things happen at the time when application just gets started.

So whatever was done using GlobalSetting.onStart and GlobalSetting.beforeStart needs to be implemented using the dependency injection.

For this, we will just provide the eager binding for the class implementation that needs to perform some tasks just before the application actually gets started.

(Eager binding is used to start up a service when an application starts.)

Then provide those implementations in the constructor of the class for which we have provided eager binding.

So lets start going step by step to replace our onStart/beforeStart implementations with dependency injected class.

Firstly create a class say, MyDBModule which extends AbstractModule in which we will bind the class implementation that will…

View original post 248 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s