CSLA Framework, Multiple Environments and a Single App

CSLA Framework, Multiple Environments and a Single App

Old forum URL: forums.lhotka.net/forums/t/9333.aspx


walkerstewart posted on Friday, August 06, 2010

Hi All,

Not sure if anyone has discussed this before (there was this post: http://forums.lhotka.net/forums/p/4413/21600.aspx#21600, but wasn't sure if it does the same thing).

I have created a single administration application that can access 4 seperate CSLA WCF environments (provided they run the same server side of things), by dynamically selecting a different WCF endpoint configured in an app.config.

I know that this may have limited use, but Just thought that I'd post it in case anyone else was interested in doing this as well.

Code Changes in CSLA:

In the WcfProxy.cs class:

FROM:

protected virtual ChannelFactory<IWcfPortal> GetChannelFactory()
{
    return new ChannelFactory<IWcfPortal>(_endPoint);
}

TO

protected virtual ChannelFactory<IWcfPortal> GetChannelFactory()
{
    string _wcfEndPoint = Environment.GetEnvironmentVariable("WcfEndPoint", EnvironmentVariableTarget.Process);

    if (_wcfEndPoint != null)
    {
        _endPoint = _wcfEndPoint;
    }

    return new ChannelFactory<IWcfPortal>(_endPoint);
}

 

In your main application, simply set the system environment variable before accessing your CSLA classes (I have a Combo box to do this since my app is an admin tool).

Environment.SetEnvironmentVariable("WcfEndPoint", "Dev" , EnvironmentVariableTarget.Process);

Environment.SetEnvironmentVariable("WcfEndPoint", "Test" , EnvironmentVariableTarget.Process);

Environment.SetEnvironmentVariable("WcfEndPoint", "Prod" , EnvironmentVariableTarget.Process);

 

And finally in the App.Config file setup your extra CSLA End Points.

<client>
      <endpoint address="net.tcp://xappd01:8142/Service/"
                binding="netTcpBinding"
                behaviorConfiguration="RBehavior"
                bindingConfiguration="RNew"
                contract="Csla.Server.Hosts.IWcfPortal" name="WcfDataPortal">
        <identity>
          <servicePrincipalName value="MYSERVICE/MyMachine" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://xappd01:8142/Service/"
                binding="netTcpBinding"
                behaviorConfiguration="RBehavior"
                bindingConfiguration="RNew"
                contract="Csla.Server.Hosts.IWcfPortal" name="Dev">
        <identity>
          <servicePrincipalName value="MYSERVICE/MyMachine" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://xappd01:8350/Service/"
                binding="netTcpBinding"
                behaviorConfiguration="RBehavior"
                bindingConfiguration="RNew"
                contract="Csla.Server.Hosts.IWcfPortal" name="Test">
        <identity>
          <servicePrincipalName value="MYSERVICE/MyMachine" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://xappd01:8551/Service/"
                binding="netTcpBinding"
                behaviorConfiguration="RBehavior"
                bindingConfiguration="RNew"
                contract="Csla.Server.Hosts.IWcfPortal" name="Qual">
        <identity>
          <servicePrincipalName value="MYSERVICE/MyMachine" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://xappd02:8650/Service/"
                binding="netTcpBinding"
                behaviorConfiguration="RBehavior"
                bindingConfiguration="RNew"
                contract="Csla.Server.Hosts.IWcfPortal" name="Prod">
        <identity>
          <servicePrincipalName value="MYSERVICE/MyMachine" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

 

Somehow I thought that it might be a little more difficult, but this turned out to be extremely straight forward. Note that the Environment Variable set applies at the process level, so as soon as the app is closed, the variable is cleared. Oh and if you don't set the Environment Variable, CSLA gets left alone and the standard "WcfDataPortal" name is used.

 

Let me know what you guys think and whether it is worthy of inclusion in the CSLA core.

Stewy

Copyright (c) Marimer LLC