我有一个加载其他库(DLL)的控制台应用程序。我使用的是Spring.NET,我的控制台应用程序非常简单,加载通过DI配置的app.config来初始化所选库。
代码
ContextRegistry.GetContext();配置(app.config)
<?xml version="1.0"?>
<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"/>
<resource uri="assembly://MyDLL/MyDLL.Config/Services.xml"/>
</context>
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">
</objects>
</spring>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup></configuration>每个库都有自己的"services.xml“文件。这些库也使用Spring.NET。
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">
<object id="componentObj"
type="MyDLL.Services.ComponentService, MyDLL"
singleton="true" />
<object
id="componentServiceHost"
type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName"
value="componentObj" />
</object>
</objects>获取excpetion“进程由于StackOverflowException而终止。”如果我注释掉<object id="componentServiceHost",则不会发生异常。
debug中的VS控制台显示
System.ServiceModel.dll中出现类型为“System.InvalidOperationException”的第一次机会异常
Spring.Core.dll中第一次出现类型为'Spring.Objects.Factory.ObjectCreationException‘的异常
Spring.Core.dll中第一次出现类型为'Spring.Objects.Factory.ObjectCreationException‘的异常
Managed (v4.0.30319)‘已退出,代码为-2147023895 (0x800703e9)。
发布于 2013-01-04 16:47:29
您还可以将spring配置放在纯xml文件中,并将其包含在库中。这样,您就可以轻松地共享此配置,而无需共享app.config。
您必须在主机控制台应用程序的配置中显式引用此配置文件,但这不是重复的。控制台应用程序host will look like this的app.config
...
<spring>
<context>
<resource uri="file://services.xml"/>
<resource uri="assembly://MyAssembly/MyDataAccess/data-access.xml"/>
</context>
</spring>请参阅spring.net文档how to configure a configuration in xml。
https://stackoverflow.com/questions/14143608
复制相似问题