Atlas configurations can be mixed allowing you to partially configure your service via the app.config and partially configure fluently.  Simply start configuring your host with the UseAppConfig configuration and then apply any fluent configurations after.

A simple example:

<configuration>
  <configSections>
    <section name="atlas" type="Atlas.Configuration.XmlConfiguration, Atlas" />
  </configSections>
  <atlas>
    <host name="MyService" displayName="My Serivce Display Name" description="A Description of this service" allowMultipleInstances="true">
      <dependencies>
        <dependency name="MSMQ" />
      </dependencies>
      <runtime accounttype="networkservice" startup="automatic" username="myusername" password="mypassword" />
    </host>
  </atlas>
</configuration>
class Program
{
    static void Main(string[] args)
    {
	var configuration = Host.UseAppConfig<MyService>()
		.WithDependencyOnServiceNamed("MSSQLSERVER")
		.BeforeStart(() => LogManager.Configure("MyLogger"))
		.WithArguments(args);
    }	
}

In this example the dependency on MSSQLSERVER has been added in the fluent configuration.  This service will be dependent on both MSSQLSERVER and MSMQ.

Also, by passing in the command line args to Atlas in configuration will override the runtime configurations made in the app.config. It is recommended to use the command line arguments for installing and/or running your service in production environments so you can override the plain text runtime configuration values.

Using the exact same configuration above we can debug, install/run in test environments, and install/run in prod environments easily and consistently.

When debugging this service in Visual Studio

Open the .csproj Project Properties, add /console to the command line arguments on the Debug Tab, then press F5

or

MyCoolService.exe /console
When installing/running this service in QA or Test environments
MyCoolService.exe /install /start

or if you prefer

MyCoolService.exe /console
When we deploy and run this service in production
MyCoolService.exe /install /start /accounttype=user /username=MyCoolServiceAccount /password=MyProdPassword
note: passing in the production username and password via command line will override what exists in the app.config file.

Last edited May 1, 2011 at 3:49 PM by amiller, version 2

Comments

Rab815 Sep 29, 2015 at 8:26 PM 
When I try running this through Visual Studio in debug mode with /console in the properties of the debug tab, I receive a Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read. error? How can I resolve this?