micronaut-projects / micronaut-sql

Projects to support SQL Database access in Micronaut
Apache License 2.0
72 stars 42 forks source link

Allow lazy loading of the data sources #442

Open ikovalyov opened 3 years ago

ikovalyov commented 3 years ago

We don't need to load datasources in our web app, or tests. We need it only if app is loaded from the command line. Unfortunately there is no way to do a lazy loading of the datasources as it is annotated with @Context

dstepanov commented 3 years ago

You should probably have a different profile where data-sources properties are only provided in the command line profile.

sdelamo commented 3 years ago

@ikovalyov

what you could do is to move the datasources block to a configuration file such as application-cli.yml.

Then it would not be loaded unless you run with environments such as cli

nhoughto commented 2 years ago

Would love this, causing a bit of pain atm with shared/inherited config, where datasource config is specified at a higher level and this triggers downstream components to try and construct the Datasource where i'd like them not to.

I believe the idiomatic micronaut way to do this is to support io.micronaut.core.util.Toggleable and then configure the data source as enabled: false at a higher level, and then enabled: true at the lower level. Lots of other areas/configurations support this Toggleable but not Datasource.