We have IDbConnection and its implementation with something that is not in IDbConnection, that is, dependence on implementation. And also some ioC (DI). Well, the knowledge that the implementation can be in any assembly is the main thing to register in the container, and this can be done in any assembly. A typical variant is that the container is prokibyvaetsya by class-recorders in assemblies (modules), where each module registers what it has.
Solution options:
1 Third party service.
This is a head-on decision. If IDbConnection does not provide the necessary data, then we simply create a service that will give us the data for the connection. That is, we create an interface like
interface IMetaDataProvider{ int GetServerVersion(IDbConnection conn); }
and we do the implementation of this in any place where there is an obvious dependency, that is, in another assembly.
interface MetaDataProvider : IMetaDataProvider{ int GetServerVersion(IDbConnection conn){ var tmp=conn as SqlConnection; ... достаем что нам надо } }
and register this service in IoC and where you just need to prokidyvaem it and the client code learns from him about the connection that he needs.
2 Extending IDbConnection through inheritance.
We make an IDbConnection successor with the properties we need.
interface IMyDbConnection : IDbConnection { int ServerVersion {get;} }
since SqlConnection does not know about our IMyDbConnection, you will have to write a wrapper.
class SqlConnWrapper : IMyDbConnection { private SqlConnection _conn; ...тут реализация IDbConnection с простым прокидываем к conn int ServerVersion => _conn.ServerVersion; }
I remind you that the wrapper can be defined in another assembly and the IoC will bind the interface and implementation. We register the SqlConnWrapper for IMyDbConnection and IDbConnection (the details of the registration depend on the container)
And those who need knowledge of ServerVersion will request IMyDbConnection for themselves, where they will obviously read the property, while others will ask for IDbConnection
3 IDbConnection Extension
just write the extension method for IDbConnection
public static class IDbConnectionEx { public int GetVersion(IDbConnection conn) { var tmp = conn as SqlConnection; ...получаем версию } }
here we must have a direct dependency on the assembly where the extension was defined, but from the extension extension we can do anything again ... for example, refer to the global DI (if there is one) where at least something like IMetaDataProvider lies and delegate the request to it , and MetaDataProvider can be in any assembly.