我试图弄清楚如何配置企业库 5.0 数据访问应用程序块。运行我的单元测试时,我收到以下错误:
Microsoft.Practices.ServiceLocation.ActivationException was caught
Message=Activation error occured while trying to get instance of type Database, key "PokerAdviserProvider"
InnerException: Microsoft.Practices.Unity.ResolutionFailedException
Message=Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "PokerAdviserProvider".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.
我得到这个的代码行:
var db = DatabaseFactory.CreateDatabase("PokerAdviserProvider");
应用程序配置:
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
</configSections>
<dataConfiguration defaultDatabase="PokerAdviserProvider" />
<connectionStrings>
<add name="PokerAdviserProvider" connectionString="server=(localhost);Initial Catalog=PokerAdviser;uid=abc;pwd=xyz"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
我一直在谷歌搜索,发现一些答案,这些设置也应该放在我的 unittest-project 的 app.Config 中,但这并没有什么不同。
我有点卡在这里,所以非常感谢任何帮助。
编辑:
我引用了正确的 dll(来自 Program Files 的那些,而不是来自源代码的),所以这也不是问题。