I’ve seen to approaches which I’m going to post in the comments to see which one is considered best. Feel free to suggest others.

  • coffeewithalex@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    This, but, with DatabaseConnection being a singleton, and preventing multiple enter clauses.

    You can ensure it’s a singleton by modifying how a new object is built, by overriding the new dunder method. If an instance exists, return that, otherwise create a new one.