Hosting custom services in Flower service host

Flower service host allows to host any WCF services. This is especially useful when a service needs to start workflows or invoke other services registered in Flower.

To host a custom service in the Flower service host, you need to define an object of type Flower.Services.Host.ServiceHostConfiguration in any service container.

createOrUpdateServiceContainer({
    name: 'Hosts',
    configuration: {
        MyServiceHost: {
            $type: 'Flower.Services.Host.ServiceHostConfiguration, Flower.Services.Host',

            // Here you need to specify an assembly qualified 
            // name of the service implementation.
            ServiceType: 'MyServiceType, MyAssembly',

            // If you'd like to host the service in the singleton mode,
            // define the service instance.
            /*
            Service: { 
                $type: 'MyServiceType, MyAssembly',

                ...
            },
            */

            // You can optionally define a list of base addresses.
            /*
            BaseAdresses: [ 
                'net.tcp://localhost:11111/MyService',
                'http://localhost:11111/MyService',
                ...
            ],
            */

            // This is a list of endpoints exposed by the service.
            Endpoints: [
                {
                    $type: 'Flower.Services.Host.ServiceEndpointConfiguration, Flower.Services.Host',

                    Contract: 'ServiceContracts.IMyService',
                    Binding: { 
                        $type: 'System.ServiceModel.NetTcpBinding' 
                    },
                    Address: 'net.tcp://localhost:11111/MyService'
                }
            ],

            // Additionally, you can specify service behaviors to be applied to
            // the service.
            /*
            Behaviors: [
                ...
            ]
            */
        }
    }
});


Then, to tell the service host to to host your service, set the 'HostedServices' property of the 'service' object in Flower.Services.Host.config.

...

<object id="service" type="Flower.Services.Host.Service, Flower.Services.Host">
    ...

    <property name="HostedServices">
        <list>
            <value>Hosts/MyServiceHost</value>
        </list>
    </property>
</object>

...


The property contains a list of paths to the service container configurations. Each instance can host multiple custom services. Flower isolates them in different application domains.

Initialization, cleanup and dependency injection

A service implementation hosted in the Flower service host may define methods to be called when an instance is initialized and released. A method marked with Flower.Workflows.InitAttribute is called when the host creates a new instance (for singletons the method is called only once before the first request); a method marked with Flower.Workflows.ReleaseAttribute is called when an instance is released by WCF (depending on per-call, per-request or singleton life-cycle the method may be called differently, but it is guaranteed that there will be no more requests to an instance for which the 'Release' method has been called).

public class MyService: IMyService 
{
    [Init]
    private void Init(
        [Service("Services/AnotherService")] IAnotherService anotherService, 
        IFlowerClient client
    ) 
    {
        ...
    }

    [Release]
    private void Release()
    {
        ...
    }

    ...
}

The initialization method may have arguments marked with Flower.Workflows.ServiceAttribute which are dependency injection targets for the service host. Services will be searched by the paths specified by the attributes and passed to the arguments. The service may also define an argument of type Flower.Client.IFlowerClient without an attribute. This attribute will be assigned the Flower client instance.

Last edited Jan 30, 2014 at 5:32 PM by dbratus, version 2

Comments

sonam1 Mar 22, 2015 at 5:57 AM 
i want develop a resource manager(as a custom service) but i dont know use which one of languages?
what language is sutaible for flower?