Sorry if this is a really basic question but it's been really getting to me. I really like the idea of DI, it really helps me with my testing but I have hit a bit of a brick wall I think. So I have two types:
Table
TableManager
Now the table object has a constructor on it like this:
Table(ITableCommandRunner tableRunner,
IQueryProvider queryProvider,
IDataReader reader,
string Name)
Now the table object pretty much only uses those objects so following the rule that you ask for what you need I pass them in. Now my TableManager object is used to Open and Close etc tables. The only thing it needs is a ITableCommandRunner so I pass that in the constructor.
TableManager(ITableCommandRunner tablrunner)
Ok that's fine but in the TableManager.OpenTable command I need call the open table commmand on the ITableCommandRunner and then construct a new Table object to pass back.
public ITable OpenTable(string tableName)
{
// Call open table command on tablerunner.
// I need a IQueryProvider and IDataReader to pass to the table.
return new Table<TEntity>(this.tablerunner, provider,reader, tableName);
}
but now in my open table command I have to make a IDataReader and IQueryProvider. If I pass them into the constructor of TableManager doesn't that violate "taking objects just to pass it down to a inner type and not really using them".
I'm not really sure how I do this. Could anyone help me with this?
I'm just not sure how I separate object construction and logic.