Bad, bad, bad getter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int SomeCountValue | |
{ | |
get | |
{ | |
if (_someCountValue == -1) | |
{ | |
using (IUnitOfWork unitOfWork = new UnitOfWork()) | |
{ | |
_someCountValue = unitOfWork.GetQueryObjectInstance<ISomeQuery>() | |
.Where(Property1, Property2, Property3, Property4 ?? 0).Select(); | |
} | |
} | |
return _someCountValue ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A property getter should never do work. It ESPECIALLY should not make a call to the database. We have methods to do work. Code calling a property getter should be able to assume that the call takes a negligible amount of time - this is clearly not the case in this getter.