tags:

views:

32

answers:

1

I have several service classes that have static methods and offer a service to the rest of my program. Most of these services involve accessing an instance of SqlDataContext (linq2sql).

First I tried instantiating this connection as a static private member per service class. This works, but it also generates a bunch of lock ups, delays and dirty object problems.

Now I went with a private instance that gets instantiated at method level. This works better in terms of lock ups and problems with dirty objects because the scope is smaller and more predictable, but this also generates a bunch of overhead in terms of connection handshakes.

How do you suggest to take on this problem?

+2  A: 

Take a look at this article by Rick Strahl - he explains the options and provides a good factory implementation to cope with creating a single request per web context/thread (depending on what you are working in.

Used this in most of the applications I have worked on where we used linq-to-sql and it seemed the right approach!

Jennifer
Thanks, will have a look :)
borisCallens
Good luck with it!
Jennifer
Was a good read, but did you check the comments too? Looks like I opened me a can of worms by choosing linq2sql. If only Hibernate was as easy to configure as drag'n drop :p
borisCallens
Personally I favour nhibernate over linq2sql but different tools for different tasks right? NHibernate will be easier to configure when all that fluent stuff works nicely. Probably won't be drag and drop though (good for us with mouse-caused rsi!)
Jennifer