c# - 配置 Enterprise Library 5.0 数据访问应用程序 block

标签 c# winforms unit-testing enterprise-library data-access-app-block

我正在尝试了解如何配置企业图书馆 5.0 数据访问应用程序 block 。 运行我的单元测试时,出现以下错误:

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>

我在谷歌上搜索了一下,找到了一些答案,这些设置也应该放在我的单元测试项目的 app.Config 中,但这并没有什么不同。

我有点卡在这里,所以非常感谢任何帮助。

编辑:

我引用了正确的 dll(来自 Program Files,而不是源代码),所以这也不是问题。

最佳答案

我终于解决了这个问题:

Error: Activation error occured while trying to get instance of type Database, key "<database name>"

Inner Exception:  Resolution of the dependency failed, type = Microsoft.Practices.EnterpriseLibrary.Data.Database

我在 Windows 7 Enlib 5.0 上运行 VS 2010。以下对我有用。想广而告之

  1. 确保您正确引用了 Microsoft.Practices.Unity.dll

  2. 获取 VS 2010 的最新服务包

关于c# - 配置 Enterprise Library 5.0 数据访问应用程序 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5608870/

相关文章:

node.js - 使用 mocha 单元测试异步 waterfall

c# - 使用 EPPlus 将 Excel 工作表格式化为表格

c# - 将字符串转换为 System.Data.SqlTypes.SqlBytes C#

c# - Linq OrderBy 不对原始集合进行排序吗?

c# - 如何使用 C# 或 VB.NET 获取当前本地主机名?

c# - 如何在 C# 中查找通用控件的标记

c# - Unity 4 添加 GameObject 和 Collider 引用

c# - 正则表达式,删除标签中的点

android - 测试一个名为 setResult 的 Activity

javascript - 在松散类型语言的单元测试中,是否应该检查方法的返回类型?