UNPKG

service-model

Version:

An object oriented web service framework inspired by Windows Communication Foundation.

107 lines (106 loc) 3.62 kB
import { RequestDispatcher } from "./dispatcher/requestDispatcher"; import { ServiceDescription } from "./description/serviceDescription"; /** * The DispatcherFactory is the primary class used to configure the service model, and is responsible for creating the * [[RequestDispatcher]] based on the service descriptions. * * <uml> * hide members * hide circle * DispatcherFactory *-- ServiceDescription : services * DispatcherFactory .> RequestDispatcher * </uml> * * ### Example * * Once our service is defined, we add it to a DispatcherFactory. We then add an endpoint to the service, * providing the name of the contract, the base address for the endpoint, and a list of endpoint behaviors. * * ```typescript * import { DispatcherFactory, RpcBehavior } from "service-model"; * * var factory = new DispatcherFactory(); * * factory.addService(CalculatorService) * .addEndpoint("Calculator", "/api/calculator", [new RpcBehavior()]); * ``` * * In this case, we add the [[RpcBehavior]] which indicates that operations on this endpoint will be available * through RPC. */ export declare class DispatcherFactory { /** * List of service descriptions configured for the dispatcher factory. */ services: ServiceDescription[]; /** * @hidden */ private _context; /** * Adds a service. * @param ctr The constructor for the service. * @param name The name of the service. If not specified the name of the constructor is used. */ addService(ctr: Constructor<any>, name?: string): ServiceDescription; /** * Creates a request dispatcher used for dispatching service requests. */ createDispatcher(): RequestDispatcher; /** * Creates a dispatch service based on the service description. * @param dispatcher The dispatcher. * @param service The service description. * @hidden */ private _createDispatchService(dispatcher, service); /** * Creates a dispatch endpoint based on an endpoint description. * @param service The dispatch service. * @param endpoint The endpoint description. * @hidden */ private _createDispatchEndpoint(service, endpoint); /** * Creates a dispatch operation based on an operation description. * @param endpoint The dispatch endpoint. * @param operation The operation description * @hidden */ private _createDispatchOperation(endpoint, operation); /** * Applies all behaviors from the description objects to the dispatch objects. * @param service The dispatch service. * @param description The service description. * @hidden */ private _applyServiceBehaviors(service, description); /** * Applies endpoint behaviors to the dispatch endpoint. * @param endpoint The dispatch endpoint. * @param description The endpoint description. * @hidden */ private _applyEndpointBehaviors(endpoint, description); /** * Applies contract behaviors to the dispatch endpoint. * @param endpoint The dispatch endpoint. * @param description The contract description. * @hidden */ private _applyContractBehaviors(endpoint, description); /** * Applies operation behaviors to the dispatch operation. * @param operation The dispatch operation. * @param description The operation description. * @hidden */ private _applyOperationBehaviors(operation, description); } /** * Interface for a constructor. */ export interface Constructor<T> { name?: string; new (...args: any[]): T; }