Class ApiExtensions
Adds some extension methods related to the ApiService functionality.
Inheritance
Inherited Members
Namespace: Celerik.NetCore.Services
Assembly: cs.temp.dll.dll
Syntax
public static class ApiExtensions
Methods
AddCoreServices<TLoggerCategory>(IServiceCollection, IConfiguration, ApiConfig)
Adds core services to the passed-in service collection.
Declaration
public static ApiBuilder<TLoggerCategory, DbContext> AddCoreServices<TLoggerCategory>(this IServiceCollection services, IConfiguration config, ApiConfig apiConfig = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The IServiceCollection to add core services to. |
| IConfiguration | config | Reference to the current IConfiguration instance. |
| ApiConfig | apiConfig | Defines the configuration needed to add core services. |
Returns
| Type | Description |
|---|---|
| ApiBuilder<TLoggerCategory, DbContext> |
Type Parameters
| Name | Description |
|---|---|
| TLoggerCategory | The type who's name is used for the logger category name. |
AddCoreServices<TLoggerCategory, TDbContext>(IServiceCollection, IConfiguration, ApiConfig)
Adds core services to the passed-in service collection.
Declaration
public static ApiBuilder<TLoggerCategory, TDbContext> AddCoreServices<TLoggerCategory, TDbContext>(this IServiceCollection services, IConfiguration config, ApiConfig apiConfig = null)
where TDbContext : DbContext
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The IServiceCollection to add core services to. |
| IConfiguration | config | Reference to the current IConfiguration instance. |
| ApiConfig | apiConfig | Defines the configuration needed to add core services. |
Returns
| Type | Description |
|---|---|
| ApiBuilder<TLoggerCategory, TDbContext> |
Type Parameters
| Name | Description |
|---|---|
| TLoggerCategory | The type who's name is used for the logger category name. |
| TDbContext | The type of DbContext. |
Exceptions
| Type | Condition |
|---|---|
| ConfigException | If there was defined a SqlServerConnectionStringKey but the connection string name is not found either in the environment variables or in the config file. |
AddValidator<TPayload, TValidator>(IServiceCollection)
Adds a Fluent Validator to this service collection.
Declaration
public static void AddValidator<TPayload, TValidator>(this IServiceCollection services)
where TPayload : class where TValidator : AbstractValidator<TPayload>
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The services where add the validator to. |
Type Parameters
| Name | Description |
|---|---|
| TPayload | The type of the payload to be validated. |
| TValidator | The type of the validator. |
GetServiceType(IConfiguration)
Gets the ApiServiceType configured into the passed-in IConfiguration object.
The following are the supported service types:
- ServiceEF: services implementing EntityFramework data access.
- ServiceHttp: services using a HttpClient.
- ServiceMock: services implementing Mock data access.
By convention, the service type is retrieved from the IConfiguration object from the property: "ServiceType".
Declaration
public static ApiServiceType GetServiceType(this IConfiguration config)
Parameters
| Type | Name | Description |
|---|---|---|
| IConfiguration | config | The configuration object where we get the ApiServiceType. |
Returns
| Type | Description |
|---|---|
| ApiServiceType | ApiServiceType stored into the passed-in IConfiguration object. |
Exceptions
| Type | Condition |
|---|---|
| ConfigException | If the ServiceType is not present in the config object, or if the value is invalid. |