Configuration using the fluent interface

Configuration of the XcoAppSpace is possible in two different ways: Either with a config string, or by using a fluent interface. This page describes configuration with the fluent interface.


The fluent configuration interface tries to guide you through the configuration process of the space by showing you all possibilities when configuring either a single service or the whole space instance. Instantiating the appspace through the fluent interface looks like this:
XcoAppSpace space = XcoAppSpace.Configure.UsingService(...)... ;
Calling the static Configure property will return a new IXcoFluentConfiguration instance that you can then use to configure everything you need. The main method you will need to call here is UsingService(). To this method allows you to hand over any service instance that should be used by the space, which can either be an instance of a predefined service like the XcoTCPTransportService, or a self-implemented service that uses e.g. the IXcoTransportService interface. After the UsingService call, a service configuration object will be returned that allows you to further configure the service - or you can again call UsingService to hand over another service instance. Note thtat there is also a generic variant of UsingService, which makes adding services that have a parameterless constructor easier.
To make this more clear, let's take a look at an example:
XcoAppSpace space = XcoAppSpace.Configure
	.UsingService(new XcoTCPTransportService()).OnPort(9001).WithName("tcp").AsDefault()
In this example first an XcoTCPTransportService instance is added, which is then configured to run on port 9001, with the name "tcp" and to be the default transport service. Then a second service instance is added (again using the UsingService() method), which is an XcoBasicSecurityService, and gets again configured with a certain policy and user store path. The methods that are available for configuring a certain service are depending on the type of service you add with UsingService(), e.g. the OnPort method will only be available when you configure a transport service like the one in this example. The available methods can be defined independently for every type of service by using extension methods. So, if you would want to write your own service, you could define such methods a well.

Instantiation details

In the above example you saw that we used a space of type XcoAppSpace. In this case the conversion of the fluent configuration instance to the XcoAppSpace instance happens automatically through an implicit operator. But this doesn't work in other cases, like when you assign your space to var or IXcoAppSpace. In this case you can use the Create() method at the end of your fluent configuration, to convert the configuration into an XcoAppSpace instance. Like this:
XcoAppSpace space1 = XcoAppSpace.Configure.UsingService<XcoTCPTransportService>().OnPort(9001); //this works without "Create()"
var space1 = XcoAppSpace.Configure.UsingService<XcoTCPTransportService>().OnPort(9001).Create(); //this only works with "Create()"
IXcoAppSpace space2 = XcoAppSpace.Configure.UsingService<XcoTCPTransportService>().OnPort(9002).Create(); //this only works with "Create()"

Combination with a config string

If you want you can even combine the fluent configuration with a config string. For this case the static method ConfigureWithConfigString() is available. You an use it like this:
XcoAppSpace space = XcoAppSpace.ConfigureWithConfigString("ccr.threadcount=4").UsingService(someService);

Service configuration overview

The following services can be configured:

Last edited Dec 21, 2012 at 1:20 PM by thomass, version 10


No comments yet.