Class ConfigurationExtensions
Extension utilities for configuration.
Inherited Members
Namespace: Cognite.Extractor.Utils
Assembly: ExtractorUtils.dll
Syntax
public static class ConfigurationExtensions
Methods
| Edit this page View SourceAddConfig<T>(IServiceCollection, string, params int[]?)
Read the config of type T from the yaml file in path
and adds it as a singleton to the service collection services
Also adds CogniteConfig, LoggerConfig and MetricsConfig configuration
objects as singletons, if they are present in the configuration
Declaration
public static T AddConfig<T>(this IServiceCollection services, string path, params int[]? acceptedConfigVersions) where T : VersionedConfig
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection |
| string | path | Path to the file |
| int[] | acceptedConfigVersions | Accepted versions |
Returns
| Type | Description |
|---|---|
| T | An instance of the configuration object |
Type Parameters
| Name | Description |
|---|---|
| T | A type that inherits from Cognite.Extractor.Configuration.VersionedConfig |
Exceptions
| Type | Condition |
|---|---|
| ConfigurationException | Thrown when the version is not valid, the yaml file is not found or in case of yaml parsing error |
AddConfig<T>(IServiceCollection, string, Type[], params int[]?)
Read the config of type T from the yaml file in path
and adds it as a singleton to the service collection services
Also adds CogniteConfig, LoggerConfig and MetricsConfig configuration
objects as singletons, if they are present in the configuration
Declaration
public static T AddConfig<T>(this IServiceCollection services, string path, Type[] types, params int[]? acceptedConfigVersions) where T : VersionedConfig
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection |
| string | path | Path to the file |
| Type[] | types | Types to look for as properties on |
| int[] | acceptedConfigVersions | Accepted versions |
Returns
| Type | Description |
|---|---|
| T | An instance of the configuration object |
Type Parameters
| Name | Description |
|---|---|
| T | A type that inherits from Cognite.Extractor.Configuration.VersionedConfig |
Exceptions
| Type | Condition |
|---|---|
| ConfigurationException | Thrown when the version is not valid, the yaml file is not found or in case of yaml parsing error |
AddExtractionRun(IServiceCollection, bool)
Add an ExtractionRun object as singleton dependency.
Declaration
public static void AddExtractionRun(this IServiceCollection services, bool setLogger)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | Service collection to add to |
| bool | setLogger | True to set a logger |
AddExtractorDependencies<T>(IServiceCollection, string?, int[]?, string?, string?, bool, bool, bool, bool, T?, Func<LoggerConfig, ILogger>?, IEnumerable<Type>?, bool, LogEventLevel)
Configure dependencies for the BaseExtractor, adding metrics, logging, state store and cognite client. Short for AddConfig, AddCogniteClient, AddStateStore, AddMetrics and AddLogger.
Declaration
public static T AddExtractorDependencies<T>(this IServiceCollection services, string? configPath, int[]? acceptedConfigVersions, string? appId, string? userAgent, bool addStateStore, bool addLogger = true, bool addMetrics = true, bool requireDestination = true, T? config = null, Func<LoggerConfig, ILogger>? buildLogger = null, IEnumerable<Type>? types = null, bool doNotAddConfig = false, LogEventLevel baseMinLevel = LogEventLevel.Fatal) where T : VersionedConfig
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | Servicecollection to add to |
| string | configPath | Path to config file |
| int[] | acceptedConfigVersions | Valid config versions. Can be null to allow all. |
| string | appId | AppId added to requests to CDF |
| string | userAgent | User agent on form Product/Version |
| bool | addStateStore | True to add state store, used if extractor reads history |
| bool | addLogger | True to add logger |
| bool | addMetrics | True to add metrics |
| bool | requireDestination | True to fail if a destination cannot be configured |
| T | config | Optional pre-defined config object to use instead of reading from file |
| Func<LoggerConfig, ILogger> | buildLogger | Optional method to build logger.
Types to look for as properties on |
| IEnumerable<Type> | types | |
| bool | doNotAddConfig | |
| LogEventLevel | baseMinLevel | Base minimum log level. This is overridden by the minimum level in the configuration. You can set this if you want to register external loggers with a lower level than the ones in config. |
Returns
| Type | Description |
|---|---|
| T | Configuration object |
Type Parameters
| Name | Description |
|---|---|
| T | Type of config object |
Exceptions
| Type | Condition |
|---|---|
| ConfigurationException | Thrown when the version is not valid, the yaml file is not found or in case of yaml parsing error |
AddRemoteConfig<T>(IServiceCollection, ILogger?, string?, IEnumerable<Type>?, string?, string?, bool, bool, RemoteConfig?, CancellationToken, params int[]?)
Read the config of type T from the yaml file in path,
or if the "type" field is set to "remote", read a minimal config file with just CogniteConfig,
then use that to fetch the config file from the configured extraction pipeline.
Either way it adds a config object to services.
Also adds CogniteConfig, LoggerConfig and MetricsConfig configuration
objects as singletons, if they are present in the configuration.
The RemoteConfigManager is added as a service to the service collection, and can be used to check for updates to configuration later.
Declaration
public static Task<T> AddRemoteConfig<T>(this IServiceCollection services, ILogger? logger, string? path, IEnumerable<Type>? types, string? appId, string? userAgent, bool setDestination, bool bufferConfigFile, RemoteConfig? remoteConfig, CancellationToken token, params int[]? acceptedConfigVersions) where T : VersionedConfig
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection |
| ILogger | logger | Logger to use during startup |
| string | path | Path to the file |
| IEnumerable<Type> | types | Types to look for as properties on |
| string | appId | Optional appid |
| string | userAgent | Optional user agent |
| bool | setDestination | Create a cognite destination based on remote config, or assume one is already provided. |
| bool | bufferConfigFile | True to store the configuration file locally so that the extractor may start even without a connection to CDF. Stored in the same directory as the config file, with name equal to temp[name-of-config-file] |
| RemoteConfig | remoteConfig | Pre-existing config object, set to null to read from |
| CancellationToken | token | Optional cancellation token. |
| int[] | acceptedConfigVersions | Accepted versions |
Returns
| Type | Description |
|---|---|
| Task<T> | An instance of the configuration object |
Type Parameters
| Name | Description |
|---|---|
| T | A type that inherits from Cognite.Extractor.Configuration.VersionedConfig |
Exceptions
| Type | Condition |
|---|---|
| ConfigurationException | Thrown when the version is not valid, the yaml file is not found or in case of yaml parsing error |