-
Notifications
You must be signed in to change notification settings - Fork 10
Requesting an item that's injected creates a new instance every time #6
Comments
One way to solve this would be to make the property wrapper a class and:
Of course this would create a new instance per |
Good catch @kerrmarin! I was expecting that new instances would be created per property, but didn't realize it was creating a new instance per access. I fixed it in 91b5841. Regarding singletons, I felt the creator of the class can create a
Thanks for contributing! |
@basememara It's probably worth documenting this behaviour. I just got caught with some low-level Repos being re-created each time, and they take in properties - so there is no trivial singleton to be had. |
That’s a really good use case, hadn’t thought of that. But if different properties are fed into it, would a second instance be stored? I’d imagine the properties would have to be part of the key name. I’ll give it more thought, but will get it documented in the meantime and leave this ticket open. Thanks for the suggestions. |
I'll be the first to say I'm using the lib wrong, but here's what I did (for example). RealmStore was fine, accountRepo was continually re-created. I left the deps as static here, but even when they're just instances hanging off AppDelegate, the same thing appears to happen.
|
Consider the following:
And a dependency with the following modules:
If you ask for the viewmodel's name you'll see that the service is created each time you request it (i.e. the module's closure is executed each time you request the dependency). In this example, you'll see "deinit" printed twice.
I believe this should not be the case.
The text was updated successfully, but these errors were encountered: