2

What happens if i dispose a HttpContextScoped() object during a session and try get an instance to it again? Will it recreate it?

Steven
  • 166,672
  • 24
  • 332
  • 435
Neil Hosey
  • 465
  • 6
  • 23

1 Answers1

0

Will it recreate it?

Of course not. How should StructureMap know that you disposed it? It can't magically hook an event on that object or wrap it in some sort of dynamic proxy for you. That's just too much magic (and don't forget the overhead). Just don't expose services to the application that implement IDisposable. IDisposable is a leaky abstraction.

Community
  • 1
  • 1
Steven
  • 166,672
  • 24
  • 332
  • 435
  • I was just hoping :) My problem is this application uses transactionScope quite alot, with a using statement, so im guessing it will auto dispose when leaving the scope of the using? Thats the problem. Is there a way around this to not dispose it? – Neil Hosey Jan 16 '13 at 11:11
  • Why do you want the scope not to be disposed? – Steven Jan 16 '13 at 12:26
  • because i want to dispose it myself when the http request is finished. I dont want it to be disposed half way through a request, then some other Repository tries to retrieve it and its null. – Neil Hosey Jan 17 '13 at 09:44
  • In that case you might have problems with the design of your application. You might be interested in [this stackoverflow question and answer](http://stackoverflow.com/questions/10585478/one-dbcontext-per-web-request-why). – Steven Jan 17 '13 at 09:56