StructureMap caching in a WinForms app

260 Views Asked by At

We've been uisng structure map in WebApps (MVC) and it's great.

I'm using the same libraries we used in the WebApps, which has structuremap all throughout it, in my winForms apps too. I'm having the obvious Memory Leaks problem, and I'm hoping I can address it via the caching in structure map.

Here are the types availible.

PerRequest - The default operation. A new instance will be created for each request. Singleton - A single instance will be shared across all requests ThreadLocal - A single instance will be created for each requesting thread. Caches the instances with ThreadLocalStorage. HttpContext - A single instance will be created for each HttpContext. Caches the instances in the HttpContext.Items collection. HttpSession - A single instance will be created for each HttpSession. Caches the instances in the HttpContext.Session collection. Use with caution. Hybrid - Uses HttpContext storage if it exists, otherwise uses ThreadLocal storage.

Needless to say other than singleton and Thread local, they seem pretty web specific.

If I want to have the instances go away is there any way to do it without have one thread per "thing" I want to do, and completely serialize them?

I know structure map and using clauses don't play well with each other, but I'm stuck with it for now. is there a known trick to making them play nice?

Thanks,

Cal-

0

There are 0 best solutions below