-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event observers in singleton are registered multiple times #157
Comments
Where are you triggering the event from? |
From entirely different object, instantiated by Library |
I mean, where are you calling |
I mean exactly that. |
Ah, ok, I understand and you are probably right. Not sure what the fix would be immediately, but I do like your idea about registering the observer in the Provider. |
@goodsoft, in case it wasn't obvious, the stop-gap solution would be the following: @Application
class App {
@Inject Library lib;
@Observes
void onEvent (SomeEvent event) {
lib.onEvent(event);
}
}
@Activity
class Main {
@Inject Library lib;
}
@Singleton
class Library {
void onEvent (SomeEvent event) {
// handle event
}
} ... until we have a better solution for this |
Consider the following situation:
In this situation event observer is registered and executed twice.
And each injection in each component registers yet another observer.
I've looked through generated code and I think the best way to solve this problem is to register observers for singletons not in component's
onCreate
method, but in singleton's...$$UnscopedProvider.get
method.This would also solve the problem of observers' persistence between different activities, services etc
The text was updated successfully, but these errors were encountered: