{"action":"created","issue":{"url":"https://api.github.com/repos/playframework/play-ebean/issues/51","labels_url":"https://api.github.com/repos/playframework/play-ebean/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/playframework/play-ebean/issues/51/comments","events_url":"https://api.github.com/repos/playframework/play-ebean/issues/51/events","html_url":"https://github.com/playframework/play-ebean/issues/51","id":99997230,"number":51,"title":"Play Ebean dependency for DI (play2.4.x)","user":{"login":"pycloux","id":178785,"avatar_url":"https://avatars.githubusercontent.com/u/178785?v=3","gravatar_id":"","url":"https://api.github.com/users/pycloux","html_url":"https://github.com/pycloux","followers_url":"https://api.github.com/users/pycloux/followers","following_url":"https://api.github.com/users/pycloux/following{/other_user}","gists_url":"https://api.github.com/users/pycloux/gists{/gist_id}","starred_url":"https://api.github.com/users/pycloux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pycloux/subscriptions","organizations_url":"https://api.github.com/users/pycloux/orgs","repos_url":"https://api.github.com/users/pycloux/repos","events_url":"https://api.github.com/users/pycloux/events{/privacy}","received_events_url":"https://api.github.com/users/pycloux/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-08-10T07:47:18Z","updated_at":"2015-11-17T19:17:49Z","closed_at":null,"body":"Hi,\r\nI am facing an issue with my DI configuration.\r\nI need to access the database in my singleton \"at initialization\".\r\nWhat is the dependency which I should set to ensure that Ebean is activated \"before\" my singleton is injected by Guice ?\r\nRegards,\r\nPYC"},"comment":{"url":"https://api.github.com/repos/playframework/play-ebean/issues/comments/157475737","html_url":"https://github.com/playframework/play-ebean/issues/51#issuecomment-157475737","issue_url":"https://api.github.com/repos/playframework/play-ebean/issues/51","id":157475737,"user":{"login":"pycloux","id":178785,"avatar_url":"https://avatars.githubusercontent.com/u/178785?v=3","gravatar_id":"","url":"https://api.github.com/users/pycloux","html_url":"https://github.com/pycloux","followers_url":"https://api.github.com/users/pycloux/followers","following_url":"https://api.github.com/users/pycloux/following{/other_user}","gists_url":"https://api.github.com/users/pycloux/gists{/gist_id}","starred_url":"https://api.github.com/users/pycloux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pycloux/subscriptions","organizations_url":"https://api.github.com/users/pycloux/orgs","repos_url":"https://api.github.com/users/pycloux/repos","events_url":"https://api.github.com/users/pycloux/events{/privacy}","received_events_url":"https://api.github.com/users/pycloux/received_events","type":"User","site_admin":false},"created_at":"2015-11-17T19:17:48Z","updated_at":"2015-11-17T19:17:48Z","body":"Hi All,\r\n\r\nSorry for the late answer.\r\nActually I had to do a lot more because of the fact that Ebean startup and shutdown is happening independently from the dependency injection.\r\n\r\nFirst I disabled the Ebean module in my configuration file:\r\n```\r\nplay.modules.disabled += \"play.db.ebean.EbeanModule\"\r\n```\r\nThe I created an injectable component (which I register in my own module) which is requested by the modules which depends on the database.\r\n\r\nWithin this module, I am dealing myself with the EBean server start (and stop):\r\n```\r\n    /**\r\n     * Initialize the database (by running patches if required)\r\n     */\r\n    private void init(Configuration configuration) {\r\n        // Register the Ebean server as the default one\r\n        ServerConfig serverConfig = getEbeanConfig().serverConfigs().get(getEbeanServerDefaultName());\r\n        Ebean.register(EbeanServerFactory.create(serverConfig), true);\r\n    }\r\n```\r\n\r\nThis solve the \"startup\" issue.\r\nBut you'll notice that by default, Ebean registers a \"shutdown hook\".\r\nThis means that it stops as soon as you ask the application to stop.\r\nThis was causing some issues in our application since the shutdown was happening completely independently of the injection order. So sometime the Ebean was shutdown while some components needed it to be up.\r\n\r\nFor this last challenge, please see https://github.com/ebean-orm/avaje-ebeanorm/issues/427 \r\n"}}