[英]using multiple app.config files
我有一個加載其他庫(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>
得到一個例外“進程由於StackOverflowException而終止。” 如果我注釋掉<object id="componentServiceHost"
,則不會發生異常。
調試中的VS控制台顯示
類型“ System.InvalidOperationException”的第一次機會異常發生在System.ServiceModel.dll中
類型為“ Spring.Objects.Factory.ObjectCreationException”的第一次機會異常發生在Spring.Core.dll中
類型為“ Spring.Objects.Factory.ObjectCreationException”的第一次機會異常發生在Spring.Core.dll中
托管(v4.0.30319)已退出,代碼-2147023895(0x800703e9)。
您還可以將spring配置放在純xml文件中,並將其包含在庫中。 這樣,您可以輕松共享此配置,而無需共享app.config。
您必須在主機控制台應用程序的配置中明確引用此配置文件,但這不是重復的。 控制台應用程序主機的app.config 將如下所示 :
...
<spring>
<context>
<resource uri="file://services.xml"/>
<resource uri="assembly://MyAssembly/MyDataAccess/data-access.xml"/>
</context>
</spring>
參見spring.net docs 如何在xml中配置配置 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.