title: SparkJava JOOQ dependency injection with Guice
body: <p>I am writing simple <em>CRUD</em> application which would fetch person records from <em>database</em> and I'm using <em>SparkJava</em> framework I have working code which fetches records from <em>database</em> but I would want to extract <em>JOOQ</em> <strong>DSLContext</strong> code and inject it as a bean and initialize it in another class in order to have more cleaner code, but I'm not sure how to achieve it here's main method which currently hold everything:</p>
  
  <pre><code> public static void main(String[] args) throws IOException {
      final BasicDataSource ds = new BasicDataSource();
      final Properties properties = new Properties();
      properties.load(BankApiApplication.class.getResourceAsStream("/application.properties"));
      ds.setDriverClassName(properties.getProperty("db.driver"));
      ds.setUrl(properties.getProperty("db.url"));
      ds.setUsername(properties.getProperty("db.username"));
      ds.setPassword(properties.getProperty("db.password"));
  
      final ConnectionProvider cp = new DataSourceConnectionProvider(ds);
      final Configuration configuration = new DefaultConfiguration()
              .set(cp)
              .set(SQLDialect.H2)
              .set(new ThreadLocalTransactionProvider(cp, true));
      final DSLContext ctx = DSL.using(configuration);
      final JSONFormat format = new JSONFormat().format(true).header(false).recordFormat(JSONFormat.RecordFormat.OBJECT);
  
      port(8080);
  
      get("/persons", (request, response) -&gt; {
          return ctx.select().from(Person.PERSON).fetch().formatJSON();
      });
  }
  </code></pre>
  
  <p>How I could extract code which initializes <strong>Datasource</strong> and configures <strong>DSLContext</strong> and instead I could just inject <strong>DSLContext</strong> or some kind of <strong>DSLContextHolder</strong> and do querying ?</p>