This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is LightSpeedContext is thread safe? Can we make it singleton? What about LightSpeedModelUnitOfWork? Can we make it singleton? What is the recommendation? LightSpeedContext and LightSpeedModelUnitOfWork should be singleton or per-request or transient? |
|
|
A LightSpeedContext instance can be shared as it just represents configuration info however if you do change some of the values on it (e.g. Logger, Cache) then this would be applied to all UnitOfWork instances which have been created by that context and this could cause unexpected behaviour. The context itself is not specifically thread-safe so if you were modifying any values on the context (e.g. a connection string) you would want to do so with some locking applied if you need to serialise the writes. Generally making this singleton instance or a single injected instance is the sensible approach (e.g. for a web app). A UnitOfWork is not thread safe and you should create and dispose of these in as small a scope as is sensible given your application design. For a web app having a UnitOfWork per request is our recommended approach.
|
|