With a previous team I worked with, whenever a new Service class was created to handle business logic between the data layer and presentation layer, something like the following was done:
class DocumentService
{
public DocumentRepository DocumentRepository { get; set; }
public DocumentService()
{
if (DocumentRepository == null) DocumentRepository = new DocumentRepository();
}
}
I never quite understood why the check for null
was there. If the constructor is being called, that means it HAS to be null..since it's a new instance, right?
Why would this be done? It seems to me like it is a redundant step, but I don't want to miss anything and pass it off as bad practice.