I'm pretty new to Aurelia (only been using it a few days) and I love it!
I know how to make a service with Aurelia, but how can I make that service a singleton that I can then share data with between multiple ViewModels?
Thanks
Just inject it
By default, the DI container assumes that everything is a singleton instance; one instance for the app. However, you can use a registration decorator to change this.
So I realized I was thinking about this too hard. I was trying to depend on the framework (Aurelia) to do all the work, but actually it was a simple ES6 class change that makes it an instance.
let instance = null;
export class SingletonService {
constructor() {
if(!instance) {
instance = this;
}
return instance;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With