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
Examples
appsettings.Development.json appsettings.Azure.json
DfltFormat
Default format provider.
public static readonly CultureInfo DfltFormat
Field Value
FrameworkVersion
Current framework version.
public static readonly string FrameworkVersion
Field Value
MainEntryPath
Main entry exe path.
public static readonly string MainEntryPath
Field Value
SETTING_BASE_FILENAME
Base settings file name.
public const string SETTING_BASE_FILENAME = "appsettings"
Field Value
XCFG_SECTION
Config extension section.
public const string XCFG_SECTION = "configExtensions"
Field Value
Properties
AppLifetime
Application IHostApplicationLifetime
public static IHostApplicationLifetime AppLifetime { get; }
Property Value
ContentRoot
Content root path.
public static string ContentRoot { get; }
Property Value
LogFactory
A LogFactory
public static ILoggerFactory LogFactory { get; }
Property Value
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
Remarks
This should be set (once) during application startup.
Settings
Configuration settings.
public static IConfigurationRoot Settings { get; }
Property Value
Setup
General application setup.
public static ApplicationSetup Setup { get; set; }
Property Value
TimeInfo
Application TimeZoneInfo
public static IAppTime TimeInfo { get; }
Property Value
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
instanceTypeTypesvcProvIServiceProvider
Returns
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
scopedFuncFunc<IServiceProvider, T, M>extraParamsobject[]
Returns
- M
The model of type
Mreturned fromscopedFunc
Type Parameters
TM
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
runSvcFunc<TSvc, TRes>
Returns
- Task<TRes>
Type Parameters
TSvcType of the service being created.
TResType 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
Returns
- Task<TRes>
Type Parameters
TSvcType of the service being created.
TResType 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.
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
keystring[]
Returns
WithServiceScope(Action<IServiceProvider>)
Exceutes the scopedAction with a (new) scoped IServiceProvider.
public static void WithServiceScope(Action<IServiceProvider> scopedAction)
Parameters
scopedActionAction<IServiceProvider>