【问题标题】:Does spring.net recurse sub directories?spring.net 是否递归子目录?
【发布时间】:2009-05-26 13:56:56
【问题描述】:

当 spring.net 框架为 asp.net 应用程序启动时,注册 IoC 容器中所有对象的组件是否会递归 web.config 中引用的所有子目录?

例如。

<spring>
  <context>
    <resource uri="~/bin/ClientService/ClientService.config"/>
    <resource uri="~/MCFModule.config"/>
  </context>
</spring>

查看调试信息(跟踪侦听器)输出,我相信答案是肯定的。

我看到的问题是,当它尝试在 '\bin\clientservice' 目录中创建实例时,即使 dll 存在于子目录中,它也会失败并显示错误消息;

'无法加载文件或程序集'log4net,Version=1.2.10.0,Culture=neutral,PublicKeyToken=1b44e1d426115821'或其依赖项之一。该系统找不到指定的文件。 '

有人有什么想法吗?

干杯

奥利

【问题讨论】:

    标签: asp.net ioc-container spring.net


    【解决方案1】:

    您还可以选择以编程方式处理程序集加载失败,使用 AppDomain 类上的AppDomain.AssemblyResolve 事件。

    例如,您可以扫描所有子目录以查找您关心的程序集。

    【讨论】:

      【解决方案2】:

      当 Spring.NET 尝试解析其配置文件中的引用时,它将使用与 .NET 程序集加载器相同的 rules。所以也许你可以尝试在你的 bin 文件夹中添加 log4net 程序集的正确引用。


      编辑:如果您希望 Spring.NET 将程序集定位在非标准位置,您可以使用 <assemblyBinding> 元素来指示位置:

      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
        <configSections>
          <sectionGroup name="spring">
            <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
            <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
          </sectionGroup>
        </configSections>
      
        <spring>
          <context>
            <resource uri="config://spring/objects"/>
          </context>
          <objects xmlns="http://www.springframework.net">
            <object id="someObject" type="log4net.Util.AppenderAttachedImpl, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
          </objects>
        </spring>
      
        <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
              <assemblyIdentity name="log4net"
                                publicKeyToken="1b44e1d426115821"
                                culture="neutral" />
              <codeBase version="1.2.10.0
                        href="file:///c:/some_special_location/log4net.dll" />
            </dependentAssembly>
          </assemblyBinding>
        </runtime>
      
      </configuration>
      

      然后你可以让容器实例化对象:

      var someObject = ContextRegistry.GetContext().GetObject("someObject");
      

      【讨论】:

      • 这也是我的理解,log4net 位于 'bin\clientservice' 目录中,无法从该子目录解析...
      猜你喜欢
      • 2017-03-26
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 2016-10-23
      • 2011-01-22
      • 2010-12-09
      • 2020-05-18
      • 1970-01-01
      相关资源
      最近更新 更多