BLun78 / Blun.ConfigurationManager

ConfigurationManager over more then one Assembly app.config

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blun.ConfigurationManager

ConfigurationManager for using App.config and Web.config of different assemblys. It have a Wcf.ChannelFactory wich use the ConfigurationManager.

Download

You can Download it from https://www.nuget.org/packages/Blun.ConfigurationManager/ or in the Visualstudio -> Package Manager Console

Install-Package Blun.ConfigurationManager

Getting Started

Load the App.config from ClassLibrary 'OtherClassLibrarayWithAppConfig' in the Application 'AppWithWebConfig'.

using System.Configuration;
using OtherClassLibrarayWithAppConfig = OtherClassLibrarayWithAppConfig.Demo;

namespace AppWithWebConfig 
{
  public class Demo
  {
    public Demo()
    {
      var config = new ConfigurationManager(
                ConfigurationManager.GetAssemblyPath(
                                    typeof(OtherClassLibrarayWithAppConfig)));
                                    
      KeyValueConfigurationElement element = 
                config.AppSettings.Settings["Getting_Started"];
    }
  }
}

Now create a WCF Channel from Assembly App.config. MS default Example

using ChannelFactory = Blun.ConfigurationManager.ServiceModel.ChannelFactory;

  public string GetData(int value)
  {
    // Loads the App.config of the Assembly of the Type 'Contract.IService1'
    var channelFactory = 
        new ChannelFactory<Contract.IService1>(@"Contract_IService1");
    var service = channelFactory.CreateChannel();
    var result = service.GetData(value);
    service.Close()
  }
  
  public string GetDataSecond(int value)
  {
    // Loads the App.config of the Assembly of the Type 'Proxy.Service1Client'
    var channelFactory = 
        new ChannelFactory<Contract.IService1>(@"Proxy_IService1", 
                                              typeof(Proxy.Service1Client));
    var service = channelFactory.CreateChannel();
    var result = service.GetData(value);
    service.Close()
  }
  
  public string GetDataThird(int value)
  {
    // Loads the App.config of the calling Assembly
    var channelFactory = 
        new ChannelFactory<Contract.IService1>(@"Proxy_IService1", 
                                              this.GetType());
    var service = channelFactory.CreateChannel();
    var result = service.GetData(value);
    service.Close()
  }
             

About

ConfigurationManager over more then one Assembly app.config

License:MIT License


Languages

Language:C# 99.1%Language:Batchfile 0.9%