0

Possible Duplicate:
Is it better to create a singleton to access unity container or pass it through the application?

We have an application that is processing various XML messages. We are using Dependency Injection along with a Singleton Factory to create instances of the related messages. We are using WCF to pick these messages off of a queue so when we launch the WCF Service it is spinning up multiple instances enabling us to process messages concurrently off of the queue.

We implemented our factory using a Singleton and just concerned we could encounter issues because we are processing multiple instances in parallel. (Issues like this is now a bottleneck, could encounter thread contention, etc)

Should we not make the Factory a Singleton? Just curious....wanted some more expert opinion on this as I am ignorant in this area.

Any suggestions / comments would be greatly appreciated.

thanks,

S

Community
  • 1
  • 1
scarpacci
  • 8,957
  • 16
  • 79
  • 144
  • Please refer to [http://stackoverflow.com/questions/1285110/singleton-factories-ok-or-bad] for answers. – perfectionist Jan 28 '12 at 17:57
  • 1
    Please state whether you are actually talking about the Singleton design pattern, or whether you mean that the container should always return the same instance of that factory (which is referred as having a 'singleton lifestyle' in DI terminology). – Steven Jan 29 '12 at 04:23

1 Answers1

1

When you're using DI, Singletons are almost never necessary.

Instead I would compose everything at the Composition Root and use appropriate lifetime management with Unity to create the equivalent of Singletons.

TrueWill
  • 25,132
  • 10
  • 101
  • 150