Should I make Enterprise Library Data Block Databa

2019-05-28 03:55发布

问题:

Can anyone clarify if Enterprise Library's Database object can be made static without any thread-safety issues?

回答1:

Yes, an Database instance is thread-safe. It is just a big factory spitting out new objects like connections. The instance itself doesn't change state after it is created. When you look at the source code you can see this clearly. The objects it produces are of course not thread-safe.



回答2:

You can, but there's no significant reason to. Database instances are cheap to create and don't hold any state.



回答3:

No don't do it. I tried it and was sorry that I did. While it was thread safe it slowed down my query requests from a web app dramatically. I thought I was being smart skirting the creation of metadata but it gummed things up instead. Now I provide a brand new instance every request and it's as happy and as fast as can be.