Spring.net 到 StructureMap 依赖注入转换

发布于 2024-10-14 05:19:31 字数 778 浏览 3 评论 0原文

美好的一天,

我如何将此弹簧配置转换为结构图配置。我有这个 spring.net 配置。

<db:provider id="DbProvider" 
      provider="System.Data.SqlClient" 
      connectionString="Data Source=(local);Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>

  <object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">  
    <property name="DbProvider" ref="DbProvider"/>                
  </object>

</objects>

我的转换是这样的,

For<Spring.Data.Core.AdoTemplate>().Use<Spring.Data.Core.AdoTemplate>().Configure.WithProperty("DBProvider").EqualTo(??????);

如何/在哪里获取 DBProvider 属性的实例?在 Spring .Net 中,它是在 xml 标签中定义的,但我不知道这是如何在结构图上完成的。

有没有人遇到过同样的问题并找到解决方案?请帮忙。

Good day,

How do i convert this spring configuration to structuremap configuration. I have this spring.net config.

<db:provider id="DbProvider" 
      provider="System.Data.SqlClient" 
      connectionString="Data Source=(local);Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>

  <object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">  
    <property name="DbProvider" ref="DbProvider"/>                
  </object>

</objects>

My conversion is like this,

For<Spring.Data.Core.AdoTemplate>().Use<Spring.Data.Core.AdoTemplate>().Configure.WithProperty("DBProvider").EqualTo(??????);

How/where do i get the instance of the DBProvider property? In Spring .Net it is defined in the xml tag but i do not know how this is done on structure map.

Has anybody encountered the same problem and found a solution? Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱不及久伴 2024-10-21 05:19:31

并不是说我曾经使用过 Structuremap,而是 Spring.NET 提供程序名称“System.Data.SqlClient”在 Spring.NET 1.3.1 中映射到下面发布的 Spring.NET 源代码中提供的 xml 配置。您可以根据需要提取信息片段(可能类型名称就是您要查找的信息)。

<object id="SqlServer-2.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
        <constructor-arg name="dbMetaData">
            <object type="Spring.Data.Common.DbMetadata">
                <constructor-arg name="productName" value="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" />
                <constructor-arg name="assemblyName" value="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="dataAdapterType" value="System.Data.SqlClient.SqlDataAdapter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
                <constructor-arg name="parameterDbType" value="System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="parameterDbTypeProperty" value="SqlDbType"/>
                <constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
                <constructor-arg name="parameterNamePrefix" value="@"/>
                <constructor-arg name="exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
        <constructor-arg name="useParameterPrefixInSql" value="true"/>     
                <constructor-arg name="bindByName" value="true"/>
                <!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
             obtaining error codes-->
                <constructor-arg name="errorCodeExceptionExpression" value="Errors[0].Number.ToString()"/>

        <!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
        <property name="ErrorCodes.BadSqlGrammarCodes">
          <value>156,170,207,208</value>
        </property>
        <property name="ErrorCodes.PermissionDeniedCodes">
          <value>229</value>
        </property>
        <property name="ErrorCodes.DataIntegrityViolationCodes">
          <value>544,2627,8114,8115</value>
        </property>
        <property name="ErrorCodes.DeadlockLoserCodes">
          <value>1205</value>
        </property>
            </object>
        </constructor-arg>

    </object>

Not that I've ever used structuremap but the Spring.NET providername "System.Data.SqlClient" is mapped in Spring.NET 1.3.1 to the xml configuration posted below as available in the Spring.NET source code. You can extract the pieces of information (probably the type names are the ones you're looking for) as needed.

<object id="SqlServer-2.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
        <constructor-arg name="dbMetaData">
            <object type="Spring.Data.Common.DbMetadata">
                <constructor-arg name="productName" value="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" />
                <constructor-arg name="assemblyName" value="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="dataAdapterType" value="System.Data.SqlClient.SqlDataAdapter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
                <constructor-arg name="parameterDbType" value="System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="parameterDbTypeProperty" value="SqlDbType"/>
                <constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
                <constructor-arg name="parameterNamePrefix" value="@"/>
                <constructor-arg name="exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
        <constructor-arg name="useParameterPrefixInSql" value="true"/>     
                <constructor-arg name="bindByName" value="true"/>
                <!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
             obtaining error codes-->
                <constructor-arg name="errorCodeExceptionExpression" value="Errors[0].Number.ToString()"/>

        <!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
        <property name="ErrorCodes.BadSqlGrammarCodes">
          <value>156,170,207,208</value>
        </property>
        <property name="ErrorCodes.PermissionDeniedCodes">
          <value>229</value>
        </property>
        <property name="ErrorCodes.DataIntegrityViolationCodes">
          <value>544,2627,8114,8115</value>
        </property>
        <property name="ErrorCodes.DeadlockLoserCodes">
          <value>1205</value>
        </property>
            </object>
        </constructor-arg>

    </object>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文