Atlas supports a robust fluent configuration.  See below for options and examples.

 

  Configuration Name Description
Required .Named(string serviceName, string displayName, string description) Sets the name, display name, and description of your service.  Parameteres displayName and description are optional. 

This is configuration is required for installing and running your service as a Windows Service.  This is optional when running your service as a console application.
Optional .WithArguments(string[] arguments) Accepts the command line arguments for determine the run mode, installation, and startup.
Optional .WithRegistrations(Action<ContainerBuilder> registration) Supports additional registrations for dependency injection.  Dependencies your service has are automatically property injected if the dependency is registered.

For constructor injection of dependencies re-register your service as IAmAHostedProcess
Optional .AllowMultipleInstances() Setting this will allow multiple instances of your process to run.  Allowing multiple instances is off by default preventing 2 instances of your service from running.
Optional .BeforeStart(Action beforeStart) Defines an action to be performed before Atlas actually starts your service.  This action is only executed when running your service, not installing your service.
Optional .WithDependencyOnServiceNamed(string serviceName) Tells Atlas that your service requires another service to be installed and running.

If the service with this name is not installed, Atlas will throw a ServiceDependencyException.

If the service is not running, Atlas will attempt to start the service.  If the dependent service is not in running state within 15 seconds Atlas will throw a ServiceDependencyException.
Optional .WithDependencyOnServiceNamed(string serviceName, TimeSpan timeToWaitForStart) Tells Atlas that your service requires another service to be installed and running and should wait for timetoWaitForStart for that service to be running, overriding the default 15 seconds .

If a service with this name is not installed, Atlas will throw a ServiceDependencyException.

If the service is not running, Atlas will attempt to start the service. If the dependent service is not in running state within the defined timeToWaitForStart Atlas will throw a ServiceDependencyException.

 

Examples:

This configures MyService to accept constructor injection using the Autofac IoC container.

var configuration = Host.Configure<MyService>()
	.WithRegistrations(b =>
		{
			b.Register(c => new MyService(c.Resolve<SomeDependency>()))
			.As<IAmAHostedProcess>()
		})
	.WithArguments(args);

This configures MyService to allow multiple instances, inject Autofac registrations, requires "MSSQLSERVER" to be installed and running, and before it starts it will configure the logger named "MyLogger" with log4net.

var configuration = Host.Configure<MyService>()
	.AllowMultipleInstances()
	.WithRegistrations(b=>b.RegisterModule(new MyServiceModule()))
	.BeforeStart(() => LogManager.Configure("MyLogger"))
	.WithDependencyOnServiceNamed("MSSQLSERVER")
	.WithArguments(args);

This configures MyService to require "MSSQLSERVER" to be installed and running and it will configure the logger named "MyLogger" with log4net before it starts.

var configuration = Host.Configure<MyService>()
	.BeforeStart(() => LogManager.Configure("MyLogger"))
	.WithDependencyOnServiceNamed("MSSQLSERVER")
	.WithArguments(args);

Last edited Apr 20, 2011 at 4:57 PM by amiller, version 5

Comments

No comments yet.