misk icon indicating copy to clipboard operation
misk copied to clipboard

Wrap DataSource to allow construction without establishing DB connection

Open damar-block opened this issue 1 year ago • 1 comments

During work on enabling PRODUCTION stage in injector test, there are multiple cases where objects require DataSource object for their construction. Currently, DataSource object is only available after connection to DB was established, which violates Guice best practices. This PR changes this module, that the provided DataSource object is a wrapper that will be initialized on service startup. It will allow consumers to require this object during construction, as long as they don't use it yet.

This PR will address cases where external code depends on DataSource, which we can't easily modify. One example is the construction of RateLimiter in MySQLBucket4jRateLimiterModule.

damar-block avatar Apr 15 '24 21:04 damar-block

I'd lean towards closing this as we discussed given it doesn't seem to add much safety (the target benefit) at the cost of a lot of boilerplate for a pseudo-Provider layer outside of Guice and new risks of later verification.

adrw avatar Apr 17 '24 19:04 adrw