Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Document correct usage of DatabaseContext #745
From the latest release to Umbraco 7.8/7.9/7.10 to address a memory leak
in the issue and comments - @zpqrtbnk states:
and in comment :
The Common Pitfalls page actually shows an good practice code snippet using DatabaseContext.Database - it would be good if we could have definitiave sample of what is good practice here ? (see https://github.com/umbraco/UmbracoDocs/blob/master/Reference/Common-Pitfalls/index.md#usage-of-singletons-and-statics)
Some clarification is needed and we don't want to confuse everyone ... Using the DatabaseContext.Database is fine in almost all scenarios except for when running code on background threads. Anywhere that we expose the
We should update the docs with regards to running code on background threads and in those cases some care will need to be taken. It is possible to be consistent however and access the database using the ScopeProvider in all scenarios, so if you want to be consistent than you can be. In which case we should also expose the ScopeProvider on base classes directly where appropriate.
I also wish to point out that using singletons like
I just don't want everyone to suddenly think that everything you've been doing is wrong. @zpqrtbnk let's try not to confuse everyone :) Yes in v8 things will be different but we aren't using v8 right now.
That’s make things clear. Currently i have issues with NoScope on a Transaction and when using scopeprovider it works.
This is inside of a apicontroller so no background tread. Is this a valid scenario? Or is using Transaction oké but it’s realy a bug at the moment!
OTOH, outside of a request, e.g. in a background thread, there is no current scope and
So, so far, and considering that the scope provider is internal: using