IoC and thread singletons

189 Views Asked by At

Several different IoC containers have support for Thread Singletons.

How do the frameworks know when a thread goes out of scope?

For instance: If I use the Thread Pool to do something, how can the container know when to create and dispose a service? The thread can be used for various of things and each task wants a new service, doesn't it?

1

There are 1 best solutions below

0
On BEST ANSWER

In Autofac you'd do this manually by creating a scope around the thread entry point (can give example if required.) Maybe not so 'magic' as implicit thread scoping, but along the lines of what you're observing here, it is much easier to understand/test/debug.

IMHO :)

Nick