问题描述
我正在尝试将自定义IDbConnection实现传递给DbContext。
我不能从抽象类DbConnection继承,因为我需要SqlConnection类中的功能。 / p>
我无法从SqlConnection继承,因为该类是密封的。
我有一个通过组合在内部使用SqlConnection的类,并实现了IDbConnection接口所以它可以使用。
有人知道为什么DbContext构造函数不接受接口IDbConnection吗?
接受不是不好的做法接口可用时的具体类?
Jamie。
I am trying to pass in a custom IDbConnection implementation into DbContext.
I cannot inherit from the abstract class DbConnection, because I need the functionality in the SqlConnection class.
I cannot inherit from SqlConnection, because the class is sealed.
I have a class that uses an SqlConnection internally through composition, and implements the IDbConnection interface so it can be used.
Does anybody know why the DbContext constructor does not accept the interface IDbConnection?
Isn't it bad practice to accept the concrete class when an interface is available?
Jamie.
这篇关于为什么DbContext接受DbConnection而不接受IDbConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!