First check-in of the code from the Obsidian Prj project.
This commit is contained in:
30
src/interfaces/Exceptions.ts
Normal file
30
src/interfaces/Exceptions.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ITSInjex } from './IDIContainer';
|
||||
|
||||
/**
|
||||
* General error class for {@link ITSInjex} interface.
|
||||
*/
|
||||
export class TSInjexError extends Error {
|
||||
/**
|
||||
* Creates a new instance of {@link TSInjexError}
|
||||
* @param message **The error message**
|
||||
*/
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'TSInjex';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error class for dependency resolution errors in {@link ITSInjex}.
|
||||
* @see {@link ITSInjex.resolve}
|
||||
*/
|
||||
export class DependencyResolutionError extends TSInjexError {
|
||||
/**
|
||||
* Creates a new instance of {@link DependencyResolutionError}
|
||||
* @param identifier **The identifier of the dependency**
|
||||
*/
|
||||
constructor(identifier: string) {
|
||||
super(`Dependency ${identifier} not found.`);
|
||||
this.name = 'TSInjexResolutionError';
|
||||
}
|
||||
}
|
||||
60
src/interfaces/IDIContainer.ts
Normal file
60
src/interfaces/IDIContainer.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Static Dependency Injection Container Interface
|
||||
*/
|
||||
export interface ITSInjex_ {
|
||||
/**
|
||||
* Get the **singleton** Dependency Injection Container
|
||||
*/
|
||||
getInstance(): ITSInjex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dependency Injection Container Interface
|
||||
*/
|
||||
export interface ITSInjex {
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated If true, the dependency is deprecated => a warning
|
||||
* is logged when the dependency is resolved.
|
||||
*/
|
||||
register<T>(identifier: string, dependency: T, deprecated?: boolean): void;
|
||||
/**
|
||||
* Register a deprecated dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated A warning is logged when the dependency is resolved.
|
||||
*/
|
||||
register<T>(identifier: string, dependency: T, deprecated?: true): void;
|
||||
/**
|
||||
* Register a dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param dependency The dependency to register.
|
||||
* @param deprecated No warning is logged when the dependency is resolved.
|
||||
*/
|
||||
register<T>(identifier: string, dependency: T, deprecated?: false): void;
|
||||
|
||||
/**
|
||||
* Resolve a dependency
|
||||
* @param identifier The identifier of the dependency
|
||||
* @param necessary If true, throws an error if the dependency is not found
|
||||
* @returns The resolved dependency or undefined if the dependency is not found
|
||||
*/
|
||||
resolve<T>(identifier: string, necessary?: boolean): T | undefined;
|
||||
/**
|
||||
* Resolve a necessary dependency.
|
||||
* @param identifier The identifier of the dependency.
|
||||
* @param necessary If true, throws an error if the dependency is not found.
|
||||
* @returns The resolved dependency.
|
||||
* @throws Error if the dependency is not found.
|
||||
*/
|
||||
resolve<T>(identifier: string, necessary?: true): T;
|
||||
/**
|
||||
* Resolve a non necessary dependency
|
||||
* @param identifier The identifier of the dependency
|
||||
* @param necessary Not necessary, does not throw an error if the dependency is not found.
|
||||
* @returns The resolved dependency or undefined if the dependency is not found
|
||||
*/
|
||||
resolve<T>(identifier: string, necessary?: false): T | undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user