Unity and Singleton

May 9, 2008 at 9:22 AM
Hi All

If we have unity to do the DI, do we still need to make it to be singleton?

Regards
Alex
May 9, 2008 at 12:01 PM
Edited May 9, 2008 at 12:12 PM
Hey Alex,

Not exactly sure what you are asking, but should take a look of following Unity help file sections:

System Design When Using a Dependency Injection Container
Setting up the Unity Container

You can download this help file Unity Application Blocks 1.0 Help.chm from Unity 1.0 Release.

If you can give a bit more explanation for your DI purpose it would be easier to answer, anyhow hope above helps…

Regards,
Alexander
May 9, 2008 at 1:30 PM
Thanks for your help.

BTW, I want to know why we need singleton pattern and when to use?

Regards
Alex


May 9, 2008 at 1:58 PM
Alex,

This is a matter of solution/technical design which is not just Unity specific, you can find more explanation of this pattern in link below and its related References and External links sections.
http://en.wikipedia.org/wiki/Singleton_pattern

Regards,
Alexander
May 9, 2008 at 2:35 PM


alexanderQX wrote:
Alex,

This is a matter of solution/technical design which is not just Unity specific, you can find more explanation of this pattern in link below and its related References and External links sections.
http://en.wikipedia.org/wiki/Singleton_pattern

Regards,
Alexander


Thanks. BTW, For the DB CRUD operations, Will you prefer to use singleton pattern?
May 9, 2008 at 3:42 PM
Edited May 9, 2008 at 3:44 PM
Hey Alex,

Your question, if I should use it for DB CRUD operations, is a bit out of context in this forum. But yes I would use singleton pattern for database objects such as configuration and solution wide static content which do not often change.

Anyhow, you need to catch up the pricipal of singleton pattern and then later to see which apporach to take to implment it into your solution, please note that the Unity is one of the possible way to implement singleton as out of the box when required for your application.

Regards,
Alexander
May 9, 2008 at 5:35 PM
I would tend to avoid singletons in general. They make it harder to write testable code, since you can't remove/mock/fake out the singleton objects.
May 10, 2008 at 4:14 AM
Thanks and it seems not necessary to use singleton now?

When do we need to use Singleton ??

Any example?
May 10, 2008 at 4:30 AM
Thanks and it seems not necessary to use singleton now?

When do we need to use Singleton ??

Any example?