-
Notifications
You must be signed in to change notification settings - Fork 40
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
Subscriber is receiving 3 messages when publisher is only sending 1 #12
Comments
I cannot help you without looking at your code. Please consider including a reproducible example which you can then zip up and attach to this issue for me to look at. |
I do have the same problem. I send only once and receive 2. |
Please provide a reproducible example for me to look at. |
Thanks for answering. Dotnet Core 2.1.101 in Startup.cs:
I have a service locator to inject singletons from Startup based on that article: https://dotnetcoretutorials.com/2018/05/06/servicelocator-shim-for-net-core/ In each service, I have:
And in the constructors of each service, I have this (just the name of the service is different in Console.WriteLine:
In SandboxService, I publish an object with a messageType property:
Here is the output:
Notice that SandboxService have only 1 token (it is the service that publish, the only one that both publish AND subscribe); in the other services, I have 2 tokens. |
just in case:
|
Please put all of that into a project where I can clone or even zip it up. |
The problem seems to be the mix of DI. In 2.1, it was not possible to inject in service like we do in controllers. This works:
This NOT works:
That's why I used the ServiceLocator to inject services in other services like this:
However, I still use the first pattern in my controllers. And I realized that I inject ActTaskService and ActWorkflowService in 2 controllers, in correponding controller (ActTaskController, ActWorfklowController) AND in SandboxController (that I use as a scratchpad). As long as I removed the 2 services from SandboxController, the class is instantiated only once. But I wonder why injection in controllers creates a new instance. |
What I'm doing is pretty basic, I have a singleton messagehub, subscriber and publisher. When the publisher publishes the message only one message is being published. For some reason however the subscriber is receiving 3 messages. I have confirmed that this is what is happening through debugging. Any ideas?
The text was updated successfully, but these errors were encountered: