Reputation: 4175
I consider using PetaPoco in a conventional web app. Saying conventional I mean
What should be the lifetime of the Database object, and that of the underlying DbConnection?
[ThreadStatic]
I especially appreciate answers from those who run production apps with PetaPoco.
Upvotes: 0
Views: 271
Reputation: 39413
Per request is the way to go
Upvotes: 2
Reputation: 39299
Database is a cheap object to create, so I just create it as needed. I use PetaPoco (or more specifically AsyncPoco so I'm not tying up threads during I/O bound work) in a busy web app and this works great for me. Others do prefer per-request though, and that should also work well.
Upvotes: 1
Reputation: 700242
You need one object per thread, but you shouldn't associate the object with the thread itself, because handling a request can start in one thread and finish in another thread.
Using one object per request would normally be the best, at least for quick request handling. However that is not always simple. If you risk leaving objects without disposing them (for example if there is an exception), it's better to use one object for a limited task where you can make sure that it is disposed properly.
Upvotes: 1