-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Any components of the app (whether added via init, services, components) will be instantiated separately for each component that depends on it. If you want some component to be shared as just a single instance, like a database connection, you need to do multiple manual steps to make that available. There is not first class support for a singleton pattern.
If you want a component to be instantiated only a single time, it needs to be a field in your app wrapped in an Arc, and you need to manually construct it. Then, you need to also declare it in the provides section with a manual access of that field, or manually implement Provides<Arc<...>>. That means the singleton needs to be defined in one place, then declared as a component of the application in at least three other places. Maybe another design could consolidate that somewhat.
The current approach for singletons is workable, so it shouldn't be replaced with something extremely obfuscated and complex just for the sake of reducing lines of code. It should be obvious how it works under the hood.