Is there any shorthand for using an extension method to instantiate and initialise an object?
My aim is to abstract-away and encapsulate the code required to instantiate and initialise an instance of MyType suitable for unit testing.
Example:
//...
//convoluted client code - I'd like to avoid the null instance creation
MyType t = null;
t = t.GetTestInstance();
//...
//extension method
public static class MyTypeExtensions
{
public static MyType GetTestInstance(this MyType t)
{
var ctorInjectedDependency = blah;
return new MyType(ctorInjectedDependency);
}
}