Show / Hide Table of Contents

Class ApiService<TLoggerCategory, TResources>

Base class for all services.

Inheritance
System.Object
ApiService<TLoggerCategory, TResources>
ApiServiceEF<TLoggerCategory, TResources, TDbContext>
Namespace: Celerik.NetCore.Services
Assembly: cs.temp.dll.dll
Syntax
public abstract class ApiService<TLoggerCategory, TResources> : IDisposable
Type Parameters
Name Description
TLoggerCategory

The type who's name is used for the logger category name.

TResources

The type used to localize string resources.

Constructors

ApiService(ApiServiceArgs<TLoggerCategory>)

Initializes a new instance of the class.

Declaration
public ApiService(ApiServiceArgs<TLoggerCategory> args)
Parameters
Type Name Description
ApiServiceArgs<TLoggerCategory> args

Encapsulates the properties to initialize a new ApiServiceArgs<TLoggerCategory>.

Properties

Config

Reference to the current IConfiguration instance.

Declaration
protected IConfiguration Config { get; }
Property Value
Type Description
IConfiguration

HttpContext

Gets a reference to the current HttpContext.

Declaration
protected HttpContext HttpContext { get; }
Property Value
Type Description
HttpContext

Logger

Reference to the current ILogger instance.

Declaration
protected ILogger<TLoggerCategory> Logger { get; }
Property Value
Type Description
ILogger<TLoggerCategory>

Mapper

Reference to the current IMapper instance.

Declaration
protected IMapper Mapper { get; }
Property Value
Type Description
IMapper

ServiceProvider

Reference to the current IServiceProvider instance.

Declaration
protected IServiceProvider ServiceProvider { get; }
Property Value
Type Description
IServiceProvider

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

Dispose(Boolean)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

Indicates whether it is disposing.

EndLog(String)

Stops logging an action.

Declaration
protected void EndLog(string message = null)
Parameters
Type Name Description
System.String message

Optional message to be logged.

Error<TStatusCode>(TStatusCode)

Creates an Error response based on the passed-in statusCode.

Declaration
protected ApiError<TStatusCode> Error<TStatusCode>(TStatusCode statusCode)
    where TStatusCode : struct, IConvertible
Parameters
Type Name Description
TStatusCode statusCode

The status code

Returns
Type Description
ApiError<TStatusCode>

Error response based on the passed-in statusCode.

Type Parameters
Name Description
TStatusCode

Type of the StatusCode property in the ApiError object.

Error<TStatusCode>(String, String)

Creates an Error response based on the passed-in localized Message and Property.

Declaration
protected ApiError<TStatusCode> Error<TStatusCode>(string message, string property)
    where TStatusCode : struct, IConvertible
Parameters
Type Name Description
System.String message

Localized Message describing the error.

System.String property

Name of the invalid property, null if the payload is null.

Returns
Type Description
ApiError<TStatusCode>

Error response based on the passed-in localized Message and Property.

Type Parameters
Name Description
TStatusCode

Type of the StatusCode property in the ApiError object.

LocalizeString(String)

Localizes the string resource with the given name.

Declaration
protected string LocalizeString(string name)
Parameters
Type Name Description
System.String name

The name of the string resource.

Returns
Type Description
System.String

Localized string resource.

LocalizeString(String, Object[])

Localizes the string resource with the given name and formatted with the supplied arguments.

Declaration
public string LocalizeString(string name, params object[] arguments)
Parameters
Type Name Description
System.String name

The name of the string resource.

System.Object[] arguments

The values to format the string with.

Returns
Type Description
System.String

The formatted string resource.

Ok<TData, TStatusCode>(Object, TStatusCode)

Declaration
protected ApiResponse<TData, TStatusCode> Ok<TData, TStatusCode>(object data, TStatusCode statusCode)
    where TData : class where TStatusCode : struct, IConvertible
Parameters
Type Name Description
System.Object data
TStatusCode statusCode
Returns
Type Description
ApiResponse<TData, TStatusCode>
Type Parameters
Name Description
TData
TStatusCode

ProcessResponse<TData, TStatusCode>(ApiResponse<TData, TStatusCode>, TStatusCode)

Declaration
protected void ProcessResponse<TData, TStatusCode>(ApiResponse<TData, TStatusCode> response, TStatusCode successMessageCode)
    where TData : class where TStatusCode : struct, IConvertible
Parameters
Type Name Description
ApiResponse<TData, TStatusCode> response
TStatusCode successMessageCode
Type Parameters
Name Description
TData
TStatusCode

StartLog()

Starts logging an action.

Declaration
protected void StartLog()

Validate<TPayload>(TPayload, out String, out String)

Validates the passed-in payload using FluentValidation.

Declaration
protected bool Validate<TPayload>(TPayload payload, out string message, out string property)
Parameters
Type Name Description
TPayload payload

The object to be validated.

System.String message

Message describing error, null if the payload is valid.

System.String property

Name of the invalid property, null if the payload is valid or if the payload is null.

Returns
Type Description
System.Boolean

True if the payload is valid.

Type Parameters
Name Description
TPayload

The type of the payload object.

In This Article
Back to top Generated by DocFX