Class NeonControllerBase
Enhances the ControllerBase class to simplify and enhance web service logging. Use this class for ASP.NET REST API. Although NeonController can be used for REST APIs as well, NeonControllerBase may have lower overhead.
Namespace: Neon.Web
Assembly: Neon.Web.dll
Syntax
[TypeFilter(typeof(LoggingExceptionFilter))]
public abstract class NeonControllerBase : ControllerBase
Remarks
This class includes the Logger property which returns a logger that can be used for logging controller events. This logger will have it's module set to WEB-CONTROLLER-NAME and can be used as a simplier alternative to doing dependency injection to your controller's constructor.
Constructors
NeonControllerBase()
Constructor.
Declaration
protected NeonControllerBase()
Properties
Logger
Returns the controller's logger.
Declaration
public ILogger Logger { get; }
Property Value
| Type | Description |
|---|---|
| ILogger |
Methods
Requires(bool, string, string, HttpStatusCode)
Throws a HttpApiException when condition is false.
Declaration
protected void Requires(bool condition, string message = null, string errorCode = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | condition | The condition being checked. |
| string | message | Optionally specifies a human readable message. |
| string | errorCode | Optionally specifies a computer readable error code string. |
| HttpStatusCode | statusCode | Optionally specifies the HTTP status code. This defaults to BadRequest. |
Remarks
note
errorCode is restricted to 1-32 characters including ASCII letters, digits,
undercores, dots, or dashes.
Exceptions
| Type | Condition |
|---|---|
| HttpApiException | Thrown when |
Requires(Func<bool>, string, string, HttpStatusCode)
Throws a HttpApiException when the predicate function returns false.
Declaration
protected void Requires(Func<bool> predicate, string message = null, string errorCode = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<bool> | predicate | Called to retrieve the condition value. |
| string | message | Optionally specifies a human readable message. |
| string | errorCode | Optionally specifies a computer readable error code string. |
| HttpStatusCode | statusCode | Optionally specifies the HTTP status code. This defaults to BadRequest. |
Remarks
note
errorCode is restricted to 1-32 characters including ASCII letters, digits,
undercores, dots, or dashes.
Exceptions
| Type | Condition |
|---|---|
| HttpApiException | Thrown when |
RequiresNotNull(object, string, string, HttpStatusCode)
Throws a HttpApiException when value is null.
Declaration
protected void RequiresNotNull(object value, string name, string errorCode = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The object value being checked. |
| string | name | Identifies the value being checked. |
| string | errorCode | Optionally specifies a computer readable error code string. |
| HttpStatusCode | statusCode | Optionally specifies the HTTP status code. This defaults to BadRequest. |
Remarks
note
errorCode is restricted to 1-32 characters including ASCII letters, digits,
undercores, dots, or dashes.
Exceptions
| Type | Condition |
|---|---|
| HttpApiException | Thrown when |
RequiresNotNull(string, string, string, HttpStatusCode)
Throws a HttpApiException when value is null or empty.
Declaration
protected void RequiresNotNull(string value, string name, string errorCode = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string value being checked. |
| string | name | Identifies the value being checked. |
| string | errorCode | Optionally specifies a computer readable error code string. |
| HttpStatusCode | statusCode | Optionally specifies the HTTP status code. This defaults to BadRequest. |
Remarks
note
errorCode is restricted to 1-32 characters including ASCII letters, digits,
undercores, dots, or dashes.
Exceptions
| Type | Condition |
|---|---|
| HttpApiException | Thrown when |