Bit of a weird one.. I've just implemented the Unit Of Work pattern in my MVC project and was just debugging it to ensure it works as intended. However, I've noticed a bit of a quirk with either my code, the pattern or visual studio..
Here an example of a repository reference I have in my UoW:
The UoW is created and disposed on each request, so one would assume the private field m_DemonstrationRepository would be null the first time the property is accessed. If I stick a breakpoint on and look at m_DemonstrationRepository it is infact null as shown below:
This is where it gets weird.. If I now hover over the public property DemonstrationRepository it claims it's no longer null (hovering over the public property previously would show it was null).. as shown below:
And finally.. if I now hover back over m_DemonstrationRepository it is no longer null!
As a further test I added some code to the constructor of DemonstrationRepository and put a break point on that to see when it's initialised. The breakpoint will hit every time as expected if I remove all other breakpoints, but if I have a breakpoint in the getter (like the pictures) and I hover over DemonstrationRepository first then the breakpoint inside the constructor won't hit! If I repeat the same request, hit the breakpoint in the getter but DON'T view the public property and just press continue, then the object is initalised as expected and the constructors breakpoint hits.
I hope that's clear enough, this has got me spinning in circles..
Thanks