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

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

问题描述

我的主要组件是Web应用程序。它采用spring.net框架,其他组件加载到其执行的应用程序域。所以很自然,这意味着所有的其他组件必须获得他们的配置值(如连接字符串和放大器;应用程序设置)。从web.config



有没有一种方法,我可以覆盖这个?有些配置可以来自web.config中;其他人必须是独立存在的。我应在制定这样的.NET程序集什么样的方法呢?我们的目标是,一旦该应用程序进入客户端环境,并在客户端决定添加组件的地方在遥远的未来,他应该能够这样做没有麻烦,并更改该程序集的配置,而不会影响其他人。



所以,最后,我必须拿出一种基于框架的方法?是否已有的东西这种效果呢?或者,我怎么去呢?什么是我要面对?


挑战的解决方案

该网站的配置文件,您可以创建自定义程序集的具体配置部分。



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



此外作为使用配置文件,您可以指定其他文件例如:


$ b $:通过在.net中



您可以使用配置源选项,在你的配置文件做配置解析器解析b

在的App.config / Web.config中



<预类=郎咸平的XML prettyprint-覆盖> <结构>
< system.serviceModel>
<服务configSource =Services.config>
< /服务>
< /system.serviceModel>
< /结构>



创建一个名为Services.config文件,并在它:



<预类=郎咸平的XML prettyprint-覆盖> <服务和GT;
<服务名称=SomeNameSpace.MyService
behaviorConfiguration =MyServiceBehaviour>
<主机>
< baseAddresses>
<添加baseAddress =HTTP://本地主机:1234 /服务/>
< / baseAddresses>
< /主机>
<端点地址=的net.tcp://本地主机:8000 /服务
结合=NetTcpBinding的
bindingConfiguration =Binding1
合同=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天全站免登陆