@athenna/ioc
Version:
Global Ioc helper for Athenna ecosystem. Built on top of awilix.
83 lines (82 loc) • 2.39 kB
TypeScript
/**
* @athenna/ioc
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type { SpyInstance, MockBuilder, StubInstance } from '@athenna/test';
import { Macroable } from '@athenna/common';
export declare class FacadeProxyHandler<T = any> extends Macroable {
/**
* The facade accessor that will be used
* to resolve the service inside the
* service container.
*/
facadeAccessor: string;
/**
* The service instance.
*/
private provider;
/**
* Creates a new instance of FacadeProxyHandler.
*/
constructor(facadeAccessor: string);
/**
* Resolve and return the service instance
* of the facade.
*/
getProvider(): T;
/**
* Returns the service instance registered
* inside the facade if exists.
*/
getFreezedProvider(): T | null;
/**
* Freezes the service instance of the
* facade until calling `unfreeze()` method.
*/
freeze(): void;
/**
* Release the service instance of the
* facade so new instances can be created.
*/
unfreeze(): void;
/**
* Resolves a service instance of the
* facade and save it to be used as stub.
*
* The stub will be used instead of resolving
* the service.
*/
stub(): StubInstance<T>;
/**
* Resolve a service instance of the facade
* and save it to be
*/
spy(): SpyInstance<T>;
/**
* Create a mock builder instance for the given method
* of the facade.
*/
when(method: keyof T): MockBuilder;
/**
* Restore the mocked facade to the original state.
*/
restore(): void;
/**
* Method called by Proxy every time that a value is changed.
* Returns the provider method with a Proxy applied in apply.
* This way we guarantee that we are working with
* the same instance when a Facade method returns this.
*/
set(_: any, key: string, value: any): boolean;
/**
* Method called by Proxy every time a new property is called.
* Returns the provider method with a Proxy applied in apply.
* This way we guarantee that we are working with
* the same instance when a Facade method returns this.
*/
get(_: any, key: string): any;
}