Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using one LINQ to SQL DataContext per WCF request and automatically calling SubmitChanges?

I've been scouring the web/SO for hours now so exuse me if I missed it...

I am looking for a concrete example of how to hook into the WCF pipeline when running as a WAS hosted in IIS so that a new LINQ to SQL DataContext is automatically created and disposed when the WCF request begins and ends.

Also, when the DataContext is being disposed would it be possible/ok to call SubmitChanges() at that point to commit any changes that have been made over the course of the request?

My main goals here are to:

  • Have the DataContext lifecycle be tied to the request
  • Hide the DataContext from my domain layer so that it is easily testable.
like image 732
Ross Hambrick Avatar asked Feb 17 '26 09:02

Ross Hambrick


1 Answers

One way to go about it would be to extend the OperationContext instance which gets created for each operation invoked in WCF. You can add extension to OperationContext. This extension can contain the DataContext instance which can be accessed and used at different location. Look at this post

like image 193
Chandermani Avatar answered Feb 20 '26 19:02

Chandermani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!