For instance, you possess an
IRepository interface. You then have a
SqlRepository class, which implements the interface, backed with a SQL database. Let us the constructor for your class requires a connection string. In case your repository makes saved procedure calls and when individuals calls are internal towards the repository, is not that the hidden dependency? Your repository is dependant not just around the database connection per the bond string, it is also based upon the database getting the correct saved methods installed. In case your backing database does not have individuals saved methods, your program will crash. Wouldso would guess what happens saved methods need to be installed for your program to operate should you did not have the
SqlRepository's code? Is the kind of hidden dependency which makes DI advocates cringe?
Um... your repository also is dependent in your database getting certain tables, and individuals tables getting certain posts. Individuals are dependancies, however they aren't particularly hidden.
Actually, individuals are a great deal larger dependencies compared to saved procedure. The repository might be rewritten to prevent requiring them, however the data really needs to be there....
Yes. However , there is no method to impose contracts on SQL databases (contracts within the object-oriented sense).
That's, we haven't any method to state that a database adjusts for an
IPersonRepository interface, therefore we can't make sure that it implements a process "dbo.GetPerson" which returns two resultsets with posts a, b, c, and d. (Or that people have permission to complete that procedure.) And then we can't require an
IPersonRepository within our connection string.
Mature object-relational mappers like (N)Hibernate solve this issue by creating domain-specific languages to explain individuals anticipation (their elaborate configuration specifications), but individuals techniques are a partial solution, simply because they can not be enforced around the database side.
This really is another part of the object-relational impedance mismatch, although one about that we haven't seen anything written.