I'm having a bit of trouble figuring out how to manage the internal dependencies that I have in a SDK I'm developing, for some reason everything I try just seems to be hard to work with.
Say I have these classes:
class Table
{
Table(string name,IQueryProvider provider, IComObject comobject) {}
}
class TableFactory
{
Table BuildTable(name) <- builds a table object.
}
the problem that I'm having is that BuildTable() method has to create a IQueryProvider and a IComObject and pass the name down. I have implemented what I hope(if I understand it correctly) the service locater pattern but if I use something like this:
BuildTable(string name)
{
IQueryProvider provider = ServiceLocator.GetInstance<IQueryProvider>();
IComObject comobject = ServiceLocator.GetInstance<IComObject>();
Table tab = new Table(name,provider,comobject);
return tab;
}
It now means that I have to have both IQueryProvider and IComObject in the ServiceLocator which makes my dependencies hard to see and test. So I created a dependency factory to create different types of objects and factories something like this:
class DependencyFactory
{
Table BuildTable(string name)
{
//call other BuildMethods to create objects.
//return new Table.
}
//Other Build methods for things like IQueryProvider, IComObject.
}
then I only have to register DependencyFactory in my service locater and then just call build methods.
Does any of this smell bad to you?
Is my first BuildTable method ok, or am I right being concerned with it.