I am writing a API over the top of a COM object and you have to pass around the COM object into pretty much every type and static method that I write so that I can test each part of my API.
Now my question is do I have an overloaded method for the one that takes the COM object but pass the IoC resolved one instead to the other one instead, so that the users of the API don't have to worry about passing in the COM object or should I remove the overloaded method and just resolve it with out the option to pass it in.
Bit hard to explain so here is an example;
Constuctor Example;
FooType(IComObject obj,string table) {}
FooType(string table) : this(Ioc.Resolve<IComObject>(), table) {}
or just
FooType(string table) : this(Ioc.Resolve<IComObject>(), table) {}
Static method example;
public static SomeType Create(IComObject obj,string table)
{ // Do some work with obj}
public static SomeType Create(string table)
{
return MyClass.Create(Ioc.Resolve<IComObject>(),table);
}
or just
public static SomeType Create(string table)
{
IComObject obj = Ioc.Resolve<IComObject>();
return MyClass.Create(Ioc.Resolve<IComObject>(),table);
}
My biggest worry with the overloading is that it's going to create a lot of methods that just froward calls. What other options do I have here or is this correct way of tackling this?
P.S I really don't want to burden the user with having to pass a instance of IComObject all around their application.