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
|
Hi, I’m trying to setup a custom connection strategy but can’t find a suitable way to apply it to UnitOfWork objects across our applications and websites. After reading this: “If desired, you can set up the connection strategy in the constructor of a strong typed unit of work, or through LightSpeedContext.UnitOfWorkFactory.” (http://www.mindscapehq.com/documentation/lightspeed/Building-Applications-with-LightSpeed/Customising-How-LightSpeed-Connects-to-the-Database) I tried the following code in my UnitOfWork constructor:
This is the connection strategy constructor:
Unfortunately, the Context property is always null which means that the Context in the custom connection strategy is null and therefore the strategy fails when LightSpeed asks it for the current Connection. Have I done something wrong? If there is a bug or limitation that prevents the unit of work constructor being used in this way, please can you explain how I could instead assign the connection strategy “through LightSpeedContext.UnitOfWorkFactory”? Essentially, I'd like to enforce the use of this WarehouseConnectionStrategy every time a unit of work is created so our application developers and LinqPad script developers don't have to think about this new complexity. Thanks, Chris PS: This is with LightSpeed50Professional-20131121 |
|
|
Hmm the documentation there looks incorrect, this wont be possible within the UnitOfWork constructor as the standard factory assigns the Context property after construction so you have done nothing wrong - unfortunately we have led you astray :( You will want to use the custom UnitOfWorkFactory to handle this. Start by creating a new class which implements IUnitOfWorkFactory. There is one method to implement:
The implementation in the standard factory is:
So something like this should be all you need:
Then when setting up your context, assign the factory so it is used for any .CreateUnitOfWork calls. e.g.
|
|
|
Excellent. That's done the job nicely. Thanks for the usual fast response. Chris |
|