I stumbled across some code and I was curious as to possible reasons why it would be this way.
There are two constructors, the main one being called in code and the second one being used in testing for dependency injection. The second constructor accepted a function that returns the object rather than an instance of the object itself.
MainConstructor()
:this(() => Factory.Current.GetInstance<IQueryService>()){
}
SecondConstructor(Func<IQueryService> getQueryService){
}
I was curious as to advantages you would get from passing in a function instead of an instance.
There are several possible benefits for doing something like this: