1

Is it ok to use SM to handle my linq datacontext lifetime or just create datacontext instance inside repository constructor? I heard from you will have memory leak problem in SM if you let it handle the datacontext. As commented by Rob Connery in this thread. See the comment below. Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

I'm using SM and asp.net mvc . It seems that im getting my memory increased eventually even context is disposed.

Community
  • 1
  • 1
Petrick Lim
  • 287
  • 4
  • 13
  • How are you handling the context? StructureMap will not automatically dispose of your context, unless you use a nested container for it. If not using nested container you need to dispose the context from the client using it. Typically you create a context at the beginning of a request and dispose of it at the end of the request. – PHeiberg Jun 09 '11 at 21:14

1 Answers1

0

I let Unity handle the lifetime of my LinqToSql context on and MVC app and have never had any problems.

In general, I don't see why an IoC container would have problems managing the lifetime of its objects. If StructureMap does (as mentioned in the thread you reference), you probably shouldn't do it then. :)

I guess your options are to either use a different framework, or let the Repository instantiate its context.

Esteban Araya
  • 29,284
  • 24
  • 107
  • 141
  • Hi Esteban, Is unity any good? does it have a rich documentation? i'm beginning to feel awkward towards SM as it lacks full documentation and complete examples :-) – Petrick Lim Jun 09 '11 at 18:46
  • @Petrick Lim: The latest version on Unity is great; I realize that all the cool kids use SM, but Unity does what we need very well. I like it because it's small (just one small DLL), and there's tons of documentation and MSDN. – Esteban Araya Jun 10 '11 at 17:37