WidgetKit and shared object instances

I’m trying to figure out the best way to handle some things in my widget. For example, I have a database that all of my widgets get their data from. Ideally I’d like to load and initialize my database once, then query the same database instance from each timeline provider. Is that possible?

So far I've tried approaching this in a couple of different ways:
  • I can’t seem to find any shared object in the widget extension. For example, in an app I can call UIApplication.shared from anywhere, or in a watchOS app there’s WKExtension.shared(). From there I can access my custom delegate, which is useful in certain situations. Does a WidgetKit extension have something like this that I'm missing?

  • I thought I might be able to create an instance of the database in the WidgetBundle and then pass it through to each timeline provider. But it seems that a Widget can’t have initialization parameters, so I don’t see how I could pass that object in.

I’m guessing this is by design—it seems like Apple wants widget extensions to be super lightweight and do work in the parent app whenever possible. But I’d like to be sure before I make some decisions on how to handle everything. (Especially since I’m also having trouble with doing the work through background app refresh.)
I ended up with a static method that reads a JSON file and returns it as a struct. That method caches the previous result in memory, and uses that result again if the JSON file is unchanged.

The JSON file is generated by my app. It contains a small subset of the data from my app's sqlite database, primarily because I wanted to avoid 0xdead10cc crashes.
WidgetKit and shared object instances
 
 
Q