0

当 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'或其依赖项之一。该系统找不到指定的文件。'

有人有任何想法吗?

干杯

奥利

4

2 回答 2

2

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

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

于 2009-06-09T04:53:52.660 回答
0

当 Spring.NET 尝试解析其配置文件中的引用时,它将使用与.NET 程序集加载器相同的规则。因此,也许您可​​以尝试在您的 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");
于 2009-05-26T14:09:23.613 回答