DrewLazzeriKitware / simulation-modeler

0 stars 0 forks source link

Sharing database classes across modules feels improvable #23

Open DrewLazzeriKitware opened 2 years ago

DrewLazzeriKitware commented 2 years ago

Both the file database and the key database are used throughout the app, and both depend on the output of the CommandValidator for instantiation.

Current approach

Both databases use this singleton decorator to make their instance available to all modules like this:

from FileDatabase import FileDatabase
FileDatabase().foo()

Except in app.py, where it's defined like:

FILEDB = None
...
FILEDB = FileDatabase(data_dir)

Cons

We must be careful to instantiate the FileDatabase() with its parameters before any of these calls happen or we'll get a confusing error.

We reference the database in different ways in different modules.

Other approaches

1) Attach to trame state object state._filedb = FileDatabase(work_dir) throws error on attempting serialization 2) Inject databases into widgets that need them.