Class AppBase
Base class for the application's root.
Inherited Members
Namespace: Kephas.Application
Assembly: Kephas.Application.dll
Syntax
public abstract class AppBase
Remarks
You should inherit this class and override at least the ConfigureAmbientServices(IAmbientServices) method.
Constructors
| Improve this Doc View SourceAppBase(IAmbientServices)
Initializes a new instance of the AppBase class.
Declaration
protected AppBase(IAmbientServices ambientServices = null)
Parameters
Type | Name | Description |
---|---|---|
IAmbientServices | ambientServices | Optional. The ambient services. If not provided then Instance is considered. |
Properties
| Improve this Doc View SourceAmbientServices
Gets the ambient services.
Declaration
public IAmbientServices AmbientServices { get; }
Property Value
Type | Description |
---|---|
IAmbientServices | The ambient services. |
AppContext
Gets a context for the application.
Declaration
public IAppContext AppContext { get; }
Property Value
Type | Description |
---|---|
IAppContext | The application context. |
Logger
Gets or sets the logger.
Declaration
protected ILogger Logger { get; set; }
Property Value
Type | Description |
---|---|
ILogger | The logger. |
Methods
| Improve this Doc View SourceBootstrapAsync(String[], CancellationToken)
Bootstraps the application asynchronously.
Declaration
public virtual Task<(IAppContext appContext, AppShutdownInstruction instruction)> BootstrapAsync(string[] rawAppArgs = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.String[] | rawAppArgs | Optional. The application arguments. |
System.Threading.CancellationToken | cancellationToken | Optional. The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.ValueTuple<IAppContext, AppShutdownInstruction>> | The asynchronous result that yields the IAppContext. |
ConfigureAmbientServices(IAmbientServices)
Configures the ambient services asynchronously.
Declaration
protected abstract void ConfigureAmbientServices(IAmbientServices ambientServices)
Parameters
Type | Name | Description |
---|---|---|
IAmbientServices | ambientServices | The ambient services. |
Remarks
Override this method to initialize the startup services, like log manager and configuration manager.
CreateAppContext(IAmbientServices)
Creates the application context.
Declaration
protected virtual IAppContext CreateAppContext(IAmbientServices ambientServices)
Parameters
Type | Name | Description |
---|---|---|
IAmbientServices | ambientServices | The ambient services. |
Returns
Type | Description |
---|---|
IAppContext | The new application context. |
FinalizeAppManagerAsync(CancellationToken)
Finalizes the application manager asynchronously.
Declaration
protected virtual Task<IAppContext> FinalizeAppManagerAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IAppContext> | A promise of the IAppContext. |
InitializeAppManagerAsync(IAppContext, CancellationToken)
Initializes the application manager asynchronously.
Declaration
protected virtual Task<IAppContext> InitializeAppManagerAsync(IAppContext appContext, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IAppContext | appContext | Context for the application. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IAppContext> | A promise of the IAppContext. |
InitializePrerequisites(String[])
Initializes the application prerequisites: the ambient services, the application context registration, the logger, other.
Declaration
protected virtual bool InitializePrerequisites(string[] rawAppArgs)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | rawAppArgs | The application arguments. |
Returns
Type | Description |
---|---|
System.Boolean | True if the initialization was performed, false if it was ignored because of subsequent calls. |
Log(LogLevel, Exception, String, Object[])
Logs the provided information.
Declaration
protected virtual void Log(LogLevel level, Exception exception, string messageFormat = null, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | level | The level. |
System.Exception | exception | The exception. |
System.String | messageFormat | The message format. |
System.Object[] | args | The arguments. |
OnCurrentDomainUnhandledException(Object, UnhandledExceptionEventArgs)
Handles the unhandled exception event.
Declaration
protected virtual void OnCurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | Source of the event. |
System.UnhandledExceptionEventArgs | e | Event information to send to registered event handlers. |
ShutdownAsync(CancellationToken)
Shuts down the application asynchronously.
Declaration
public virtual Task<IAppContext> ShutdownAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken | Optional. The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IAppContext> | A promise of the IAppContext. |
WaitForShutdownSignalAsync(CancellationToken)
Waits for the shutdown signal asynchronously.
Declaration
protected virtual Task<AppShutdownInstruction> WaitForShutdownSignalAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken | Optional. The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<AppShutdownInstruction> | An asynchronous result that yields the shutdown instruction. |