.net 程序集和个人配置 [英] .net assemblies and individual configuration

查看:22
本文介绍了.net 程序集和个人配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要程序集是一个 Web 应用程序.它使用 spring.net 框架将其他程序集加载到其执行应用程序域中.所以很自然地,这意味着所有那些其他程序集都必须从 web.config 获取它们的配置值(例如连接字符串和应用设置).

有什么方法可以覆盖它吗?一些配置可以来自 web.config;其他人必须分开居住.我应该采用什么样的方法来开发这样的 .net 程序集?目标是,一旦此应用程序进入客户端环境,并且客户端决定在遥远的将来在某处添加程序集,他应该能够毫不费力地添加程序集,并在不影响其他程序集的情况下更改该程序集的配置.

所以最终我必须提出一种基于框架的方法?已经有这种效果了吗?或者我该怎么做?我将面临哪些挑战?

解决方案

Web 配置文件允许您创建自定义程序集特定的配置部分.

查看 http://msdn.microsoft.com/en-us/library/2tw134k3.aspx 详情

此外,您可以指定其他文件作为配置文件,以供 .net 中的配置解析器使用和解析

您可以使用配置文件中的配置源选项来执行此操作:例如

在 App.config/Web.config 中

<system.serviceModel><services configSource="Services.config" ></服务></system.serviceModel></配置>

创建一个名为 Services.config 的文件,并在其中:

<服务名称="SomeNameSpace.MyService"behaviorConfiguration="MyServiceBehaviour"><主机><基地址><add baseAddress="http://localhost:1234/service"/></baseAddresses></host><端点地址="net.tcp://localhost:8000/service"绑定=netTcpBinding"bindingConfiguration="Binding1"contract="SomeNameSpace.IService"/></服务></服务>

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?

解决方案

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>

这篇关于.net 程序集和个人配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆