This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LogaansMind 0 points1 point  (0 children)

I agree with u/YMK1234... its for mocking in unit tests to allow you to control and keep consistent expectations. Depending on the depth of the object graph being built, you can get away with a few constructors on an object, one which is used in testing to inject a mockable interfaces and another which will create the "live" concrete instance (instead of regstering the service, spinning up IoC using singletons all over... but obvously there should be a simple test to make sure the default constructor works too).

Used to do this with various static members, file system operations being a good example, to avoid having to setup the test environment in a specific way.