Table of Contents

Class App

Namespace
Tlabs
Assembly
Tlabs.Core.dll

Application global services.

public static class App
Inheritance
App
Inherited Members

Fields

APP_ENV_VAR

Environment variable to control loading of an additional settings file with the naming pattern:

appsettings.{%APP_ENV_VAR%}.json
.
public const string APP_ENV_VAR = "ASPNETCORE_ENVIRONMENT"

Field Value

string

Examples

appsettings.Development.json appsettings.Azure.json

DfltFormat

Default format provider.

public static readonly CultureInfo DfltFormat

Field Value

CultureInfo

FrameworkVersion

Current framework version.

public static readonly string FrameworkVersion

Field Value

string

MainEntryPath

Main entry exe path.

public static readonly string MainEntryPath

Field Value

string

SETTING_BASE_FILENAME

Base settings file name.

public const string SETTING_BASE_FILENAME = "appsettings"

Field Value

string

XCFG_SECTION

Config extension section.

public const string XCFG_SECTION = "configExtensions"

Field Value

string

Properties

AppLifetime

public static IHostApplicationLifetime AppLifetime { get; }

Property Value

IHostApplicationLifetime

ContentRoot

Content root path.

public static string ContentRoot { get; }

Property Value

string

LogFactory

A LogFactory

public static ILoggerFactory LogFactory { get; }

Property Value

ILoggerFactory

Remarks

This is the central ILoggerFactory that has been setup for the application.

NOTE: To obtain a singleton instance of ILogger<TCategoryName> for type T it is best to call Logger<T>()

ServiceProv

Application wide IServiceProvider

public static IServiceProvider ServiceProv { get; }

Property Value

IServiceProvider

Remarks

This should be set (once) during application startup.

Settings

Configuration settings.

public static IConfigurationRoot Settings { get; }

Property Value

IConfigurationRoot

Setup

General application setup.

public static ApplicationSetup Setup { get; set; }

Property Value

ApplicationSetup

TimeInfo

Application TimeZoneInfo

public static IAppTime TimeInfo { get; }

Property Value

IAppTime

Methods

CreateResolvedInstance(Type, IServiceProvider?)

Create a new instance of instanceType with any service dependencies from a suitable ctor resolved from the optional svcProv (defaults to ServiceProv).

public static object CreateResolvedInstance(Type instanceType, IServiceProvider? svcProv = null)

Parameters

instanceType Type
svcProv IServiceProvider

Returns

object

FromScopedServiceInstance<T, M>(Func<IServiceProvider, T, M>, params object[])

Exceutes the scopedFunc with a service instance of type T from a (new) service scope.

public static M FromScopedServiceInstance<T, M>(Func<IServiceProvider, T, M> scopedFunc, params object[] extraParams)

Parameters

scopedFunc Func<IServiceProvider, T, M>
extraParams object[]

Returns

M

The model of type M returned from scopedFunc

Type Parameters

T
M

Logger<T>()

Returns a ILogger<TCategoryName> for T

public static ILogger<T> Logger<T>()

Returns

ILogger<T>

Type Parameters

T

Remarks

The logger returned is internally managed as singleton.

RunBackgroundService<TSvc, TRes>(Func<TSvc, TRes>)

Runs an asynchronous background service by calling runSvc.

public static Task<TRes> RunBackgroundService<TSvc, TRes>(Func<TSvc, TRes> runSvc) where TRes : class

Parameters

runSvc Func<TSvc, TRes>

Returns

Task<TRes>

Type Parameters

TSvc

Type of the service being created.

TRes

Type of the service result (returned from runSvc).

Remarks

An instance of the service of type TSvc is created using a ctor whose parameters are getting resolved via dependency injection from ServiceProv. (It is also okay if TSvc only has a default ctor.)

NOTE: If TSvc is IDisposable it gets disposed after runSvc was invoked.

RunBackgroundService<TSvc, TRes>(Type, Func<TSvc, TRes>)

Runs an asynchronous background service by calling runSvc.

public static Task<TRes> RunBackgroundService<TSvc, TRes>(Type svcType, Func<TSvc, TRes> runSvc) where TRes : class

Parameters

svcType Type
runSvc Func<TSvc, TRes>

Returns

Task<TRes>

Type Parameters

TSvc

Type of the service being created.

TRes

Type of the service result (returned from runSvc).

Remarks

An instance of the service of type svcType is created using a ctor whose parameters are getting resolved via dependency injection from ServiceProv.

This overload of the method is to be used in cases where svcType is not known at compile time, but must be assignable to TSvc.

(It is also okay if svcType only has a default ctor.)

NOTE: If svcType is IDisposable it gets disposed after runSvc was invoked.

SettingsEntry(params string[])

Configuration entry.

[Obsolete("Use configuration extension method", false)]
public static string SettingsEntry(params string[] key)

Parameters

key string[]

Returns

string

WithServiceScope(Action<IServiceProvider>)

Exceutes the scopedAction with a (new) scoped IServiceProvider.

public static void WithServiceScope(Action<IServiceProvider> scopedAction)

Parameters

scopedAction Action<IServiceProvider>