Class WebApiModuleBase
A module using objects derived from WebApiController as collections of handler methods.
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
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 |
See Also
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
See Also
RegisterControllerType(Type, Func<WebApiController>)
Registers a controller type using a factory method.
In order for registration to be successful:
controllerTypemust be a subclass of WebApiController;controllerTypemust not be a generic type definition;factory's return type must be eithercontrollerTypeor a subclass ofcontrollerType.
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 |
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 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<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
See Also
RegisterControllerType<TController>(Func<TController>)
Registers a controller type using a factory method.
In order for registration to be successful:
TControllermust be a subclass of WebApiController;TControllermust not be a generic type definition;factory's return type must be eitherTControlleror a subclass ofTController.
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 |
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 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.