Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is the imessagebroker a singleton or a singleton?


Asked by Dalton Terry on Dec 11, 2021 FAQ



IMessageBroker is Singleton in my DI configuration. Will the QueueClient.CreateFromConnectionString method create a new object every time or reuse a connection internally based on the same ConnectionString or queuename? Is there anything I can do better on this code?
Accordingly,
Since an instance of a subclass is an instance of your superclass, you could find multiple instances of the Singleton. One of the strengths of the Singleton design pattern, as opposed to static methods, is that if you change your mind and want more than one, the Singleton class can be easily altered.
In addition, One of the ways you use a singleton is to cover an instance where there must be a single "broker" controlling access to a resource. Singletons are good in loggers because they broker access to, say, a file, which can only be written to exclusively.
In fact,
The Singleton's purpose is to control object creation, limiting the number of objects to only one. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources,...
And,
But still the fact is that such Singleton provides a global variable. And moreover you can not create second or third instance. There is only one instance. For android there is more dangerous problem with stateful mutable Singleton.