Unosquare
    Show / Hide Table of Contents

    Class WebApiModuleBase

    A module using objects derived from WebApiController as collections of handler methods.

    Inheritance
    Object
    WebApiModuleBase
    WebApiModule
    Namespace: EmbedIO.WebApi
    Syntax
    public abstract class WebApiModuleBase : RoutingModuleBase

    Constructors

    WebApiModuleBase(String)

    Initializes a new instance of the WebApiModuleBase class, using the default response serializer.

    Declaration
    protected WebApiModuleBase(string baseRoute)
    Parameters
    Type Name Description
    String baseRoute

    The base route served by this module.

    See Also
    BaseRoute

    WebApiModuleBase(String, ResponseSerializerCallback)

    Initializes a new instance of the WebApiModuleBase class, using the specified response serializer.

    Declaration
    protected WebApiModuleBase(string baseRoute, ResponseSerializerCallback serializer)
    Parameters
    Type Name Description
    String baseRoute

    The base route served by this module.

    ResponseSerializerCallback serializer

    A ResponseSerializerCallback used to serialize the result of controller methods returning langword_csharp_object or Task<object>.

    See Also
    BaseRoute

    Properties

    ControllerCount

    Gets the number of controller types registered in this module.

    Declaration
    public int ControllerCount { get; }
    Property Value
    Type Description
    Int32

    Serializer

    A ResponseSerializerCallback used to serialize the result of controller methods returning values.

    Declaration
    public ResponseSerializerCallback Serializer { get; }
    Property Value
    Type Description
    ResponseSerializerCallback

    Methods

    RegisterControllerType(Type)

    Registers a controller type using a constructor.

    In order for registration to be successful, the specified controllerType:

    • must be a subclass of WebApiController;
    • must not be an abstract class;
    • must not be a generic type definition;
    • must have a public parameterless constructor.

    Declaration
    protected void RegisterControllerType(Type controllerType)
    Parameters
    Type Name Description
    Type controllerType

    The type of the controller.

    Remarks

    A new instance of controllerType will be created for each request to handle, and dereferenced immediately afterwards, to be collected during next garbage collection cycle.

    controllerType is not required to be thread-safe, as it will be constructed and used in the same synchronization context. However, since request handling is asynchronous, the actual execution thread may vary during execution. Care must be exercised when using thread-sensitive resources or thread-static data.

    If controllerType implements , its Dispose method will be called when it has finished handling a request.

    See Also
    RegisterControllerType(Type, Func<WebApiController>)
    RegisterControllerType<TController>()

    RegisterControllerType(Type, Func<WebApiController>)

    Registers a controller type using a factory method.

    In order for registration to be successful:

    • controllerType must be a subclass of WebApiController;
    • controllerType must not be a generic type definition;
    • factory's return type must be either controllerType or a subclass of controllerType.

    Declaration
    protected void RegisterControllerType(Type controllerType, Func<WebApiController> factory)
    Parameters
    Type Name Description
    Type controllerType

    The type of the controller.

    Func<WebApiController> factory

    The factory method used to construct instances of controllerType.

    Remarks

    factorywill be called once for each request to handle in order to obtain an instance of controllerType. The returned instance will be dereferenced immediately after handling the request.

    controllerType is not required to be thread-safe, as it will be constructed and used in the same synchronization context. However, since request handling is asynchronous, the actual execution thread may vary during execution. Care must be exercised when using thread-sensitive resources or thread-static data.

    If controllerType implements , its Dispose method will be called when it has finished handling a request. In this case it is recommended that factory return a newly-constructed instance of controllerType at each invocation.

    If controllerType does not implement , factory may employ techniques such as instance pooling to avoid the overhead of constructing a new instance of controllerType at each invocation. If so, resources such as file handles, database connections, etc. should be freed before returning from each handler method to avoid starvation.

    See Also
    RegisterControllerType(Type)
    RegisterControllerType<TController>(Func<TController>)

    RegisterControllerType<TController>()

    Registers a controller type using a constructor.

    In order for registration to be successful, the specified controller type:

    • must be a subclass of WebApiController;
    • must not be an abstract class;
    • must not be a generic type definition;
    • must have a public parameterless constructor.

    Declaration
    protected void RegisterControllerType<TController>()
        where TController : WebApiController, new()
    Type Parameters
    Name Description
    TController

    The type of the controller.

    Remarks

    A new instance of TController will be created for each request to handle, and dereferenced immediately afterwards, to be collected during next garbage collection cycle.

    TController is not required to be thread-safe, as it will be constructed and used in the same synchronization context. However, since request handling is asynchronous, the actual execution thread may vary during execution. Care must be exercised when using thread-sensitive resources or thread-static data.

    If TController implements , its Dispose method will be called when it has finished handling a request.

    See Also
    RegisterControllerType<TController>(Func<TController>)
    RegisterControllerType(Type)

    RegisterControllerType<TController>(Func<TController>)

    Registers a controller type using a factory method.

    In order for registration to be successful:

    • TController must be a subclass of WebApiController;
    • TController must not be a generic type definition;
    • factory's return type must be either TController or a subclass of TController.

    Declaration
    protected void RegisterControllerType<TController>(Func<TController> factory)
        where TController : WebApiController
    Parameters
    Type Name Description
    Func<TController> factory

    The factory method used to construct instances of TController.

    Type Parameters
    Name Description
    TController

    The type of the controller.

    Remarks

    factorywill be called once for each request to handle in order to obtain an instance of TController. The returned instance will be dereferenced immediately after handling the request.

    TController is not required to be thread-safe, as it will be constructed and used in the same synchronization context. However, since request handling is asynchronous, the actual execution thread may vary during execution. Care must be exercised when using thread-sensitive resources or thread-static data.

    If TController implements , its Dispose method will be called when it has finished handling a request. In this case it is recommended that factory return a newly-constructed instance of TController at each invocation.

    If TController does not implement , factory may employ techniques such as instance pooling to avoid the overhead of constructing a new instance of TController at each invocation. If so, resources such as file handles, database connections, etc. should be freed before returning from each handler method to avoid starvation.

    See Also
    RegisterControllerType<TController>()
    RegisterControllerType(Type, Func<WebApiController>)

    Comments

    Back to top Copyright © 2017-2019 Unosquare