Show / Hide Table of Contents

Class ServiceFactoryExtensions

Implements extensions for the IServiceFactory to call service methods asynchronously or synchronously .

Inheritance
System.Object
ServiceFactoryExtensions
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Sartorius.SAF.Extensions
Assembly: Sartorius.SAF.dll
Syntax
public static class ServiceFactoryExtensions
Remarks

The implementation of the IServiceFactory must be obtained using the MEF import mechanism, for example using the System.ComponentModel.Composition.ImportingConstructorAttribute.

Examples

The following example illustrates how to call asynchronously service function that use security token .

The following example illustrates how to call asynchronously service function.

        var result = await ServiceFactory.CallAsync<IDummyService, String>(service => service.DoFunc());

The following example illustrates how to call asynchronously service function without result.

        await ServiceFactory.CallAsync<IDummyService>(service => service.DoAction());

The following example illustrates how to call synchronously service function that use security token.

The following example illustrates how to call synchronously service function.

        var result = ServiceFactory.Call<IDummyService, String>(service => service.DoFunc());

The following example illustrates how to call synchronously service function without result.

        ServiceFactory.Call<IDummyService>(service => service.DoAction());

Methods

View Source

Call<TService>(IServiceFactory, Action<TService>)

Call synchronously a given service TService without result.

Declaration
public static void Call<TService>(this IServiceFactory serviceFactory, Action<TService> callOnService)
    where TService : class
Parameters
Type Name Description
IServiceFactory serviceFactory

A implementation of IServiceFactory

System.Action<TService> callOnService

Encapsulate the service method that should be called.

Type Parameters
Name Description
TService

A type of service.

View Source

Call<TService, TResult>(IServiceFactory, Func<TService, TResult>)

Call synchronously a given service TService.

Declaration
public static TResult Call<TService, TResult>(this IServiceFactory serviceFactory, Func<TService, TResult> callOnService)
    where TService : class
Parameters
Type Name Description
IServiceFactory serviceFactory
System.Func<TService, TResult> callOnService

Encapsulate the service method that should be called.

Returns
Type Description
TResult

A result of service.

Type Parameters
Name Description
TService

A type of service.

TResult

A type of result.

View Source

CallAsync<TService>(IServiceFactory, Action<TService>)

Call asynchronously a given service TService.

Declaration
public static Task CallAsync<TService>(this IServiceFactory serviceFactory, Action<TService> callOnService)
    where TService : class
Parameters
Type Name Description
IServiceFactory serviceFactory
System.Action<TService> callOnService

Encapsulate the service method that should be called.

Returns
Type Description
System.Threading.Tasks.Task

A instance of System.Threading.Tasks.Task

Type Parameters
Name Description
TService

A type of service.

View Source

CallAsync<TService, TResult>(IServiceFactory, Func<TService, TResult>)

Call asynchronously a given service TService.

Declaration
public static Task<TResult> CallAsync<TService, TResult>(this IServiceFactory serviceFactory, Func<TService, TResult> callOnService)
    where TService : class
Parameters
Type Name Description
IServiceFactory serviceFactory
System.Func<TService, TResult> callOnService

Encapsulate the service method that should be called.

Returns
Type Description
System.Threading.Tasks.Task<TResult>

A result of service.

Type Parameters
Name Description
TService

A type of service.

TResult

A type of result.

  • View Source
Back to top Generated by DocFX