.net assemblies and individual configuration

此生再无相见时 提交于 2019-12-20 07:32:16

问题


My primary assembly is a web application. It uses spring.net framework to load other assemblies into its executing app domain. So naturally this means all those other assemblies must get their config values (for e.g. connection strings & app settings) from the web.config.

Is there a way I can override this? Some of the configurations can come from the web.config; others must reside separately. What kind of an approach should I take in developing such .net assemblies? The goal is, once this application goes into the client environment, and the client decides to add assemblies somewhere in the distant future, he should be able to do so without hassles, and change the configuration for that assembly without affecting the others.

So ultimately I must come out with a kind of framework-based approach? Is there already something to this effect? Or how do I go about this? What are the challenges I'd be faced with?


回答1:


The web config file allows you to create custom assembly specific configuration sections.

Check out http://msdn.microsoft.com/en-us/library/2tw134k3.aspx for details

Additionally you can specify other files as configuration files to be used and parsed by the configuration parser in .net

You can do this using the config source option in your config files: e.g.

in App.config/Web.config

<configuration>
  <system.serviceModel>
    <services configSource="Services.config" >
    </services> 
  </system.serviceModel>
</configuration>

Create a file called Services.config and in it:

<services>
  <service name="SomeNameSpace.MyService"
           behaviorConfiguration="MyServiceBehaviour">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:1234/service"/>
      </baseAddresses>
    </host>
    <endpoint address="net.tcp://localhost:8000/service"
              binding="netTcpBinding"
              bindingConfiguration="Binding1"
              contract="SomeNameSpace.IService" />
  </service>
</services>


来源:https://stackoverflow.com/questions/10672564/net-assemblies-and-individual-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!