简体   繁体   中英

using multiple app.config files

I have a console application that loads other libraries (DLL's). I'm using Spring.NET. My console application is very simple, load the app.config that is configured through DI to initialize the chosen library.

Code

ContextRegistry.GetContext();

Configuration (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>

Each library has its own "services.xml" file. These libraries also use 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>

Getting a excpetion "Process is terminated due to StackOverflowException." If I comment out the <object id="componentServiceHost" , the exception does not occur.

The VS console in debug shows

A first chance exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll

A first chance exception of type 'Spring.Objects.Factory.ObjectCreationException' occurred in Spring.Core.dll

A first chance exception of type 'Spring.Objects.Factory.ObjectCreationException' occurred in Spring.Core.dll

Managed (v4.0.30319)' has exited with code -2147023895 (0x800703e9).

You can also place spring configuration in plain xml files and include those with your library. This way, you can easily share this configuration without the need of sharing an app.config.

You do have to explicitly reference this configuration file in the configuration of your host console application, but that's no duplication. The app.config of your console application host will look like this :

...
<spring>
  <context>
    <resource uri="file://services.xml"/>
    <resource uri="assembly://MyAssembly/MyDataAccess/data-access.xml"/>
  </context>
</spring>

See the spring.net docs how to configure a configuration in xml .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM