File

projects/wms-framework/src/lib/regionsframework/test/SimpleDIContainerMocks.ts

Index

Properties
Methods

Constructor

Public constructor()

Properties

Private creationDate
Type : Date
Default value : new Date()

Methods

as_IExplicitInterface1
as_IExplicitInterface1()
Decorators :
@asExplicitImplementation('Sample.IExplicitInterface1')
as_IExplicitInterface2
as_IExplicitInterface2()
Decorators :
@asExplicitImplementation('Sample.IExplicitInterface2')
DoSomething_ExplicitImplementationOfIExplicitInterface
DoSomething_ExplicitImplementationOfIExplicitInterface()
Returns : string
import { inject, injectable } from 'tsyringe';
import { asExplicitImplementation } from '../../decorators/AsExplicitImplementation';

export interface IMyInterface {
  DoSomething(): string;
}

@injectable()
export class MyClassImplementation implements IMyInterface {
  public static idGenerator = 0;

  private instanceId: number;

  constructor() {
    MyClassImplementation.idGenerator++;
    this.instanceId = MyClassImplementation.idGenerator;
  }

  public DoSomething(): string {
    return `Id ${this.instanceId}`;
  }
}

@injectable()
export class MyDisposableImplementation implements IMyInterface {
  public msg = 'NOT DISPOSED';

  public DoSomething(): string {
    return;
  }

  public Dispose(): void {
    this.msg = 'DISPOSED!';
  }
}

@injectable()
export class MyServiceImpl1 {
  constructor(@inject('IMyInterface') public myType: IMyInterface) {}
}

@injectable()
export class MyServiceImpl2 {
  constructor(public myType: MyClassImplementation) {}
}

// Dummies for explicit interfaces tests

export interface IExplicitInterface1 {
  DoSomething(): string;
}

export interface IExplicitInterface2 {
  DoSomething(): string;
}

@injectable()
export class BasicExplicitImplement {
  private creationDate: Date = new Date();
  public constructor() {
    this.creationDate = new Date();
  }
  DoSomething_ExplicitImplementationOfIExplicitInterface(): string {
    return `Creation date from explicit : ${this.creationDate}`;
  }

  @asExplicitImplementation('Sample.IExplicitInterface1')
  as_IExplicitInterface1(): IExplicitInterface1 {
    return new BasicExplicitImplement_IExplicitInterface1Wrapper(this);
  }
}

export class BasicExplicitImplement_IExplicitInterface1Wrapper
  implements IExplicitInterface1
{
  constructor(public instance: BasicExplicitImplement) {}
  isExplicitInterfaceImplementationWrapper = true;
  DoSomething(): string {
    return this.instance.DoSomething_ExplicitImplementationOfIExplicitInterface();
  }
}

@injectable()
export class MultipleExplicitImplement {
  private creationDate: Date = new Date();
  public constructor() {
    this.creationDate = new Date();
  }
  DoSomething_ExplicitImplementationOfIExplicitInterface(): string {
    return `Creation date from explicit : ${this.creationDate}`;
  }

  @asExplicitImplementation('Sample.IExplicitInterface1')
  as_IExplicitInterface1(): IExplicitInterface1 {
    return new MultipleExplicitImplement_IExplicitInterface1Wrapper(this);
  }

  @asExplicitImplementation('Sample.IExplicitInterface2')
  as_IExplicitInterface2(): IExplicitInterface1 {
    return new MultipleExplicitImplement_IExplicitInterface2Wrapper(this);
  }
}

export class MultipleExplicitImplement_IExplicitInterface1Wrapper
  implements IExplicitInterface1
{
  constructor(public instance: MultipleExplicitImplement) {}
  isExplicitInterfaceImplementationWrapper = true;
  DoSomething(): string {
    return this.instance.DoSomething_ExplicitImplementationOfIExplicitInterface();
  }
}

export class MultipleExplicitImplement_IExplicitInterface2Wrapper
  implements IExplicitInterface1
{
  constructor(public instance: MultipleExplicitImplement) {}
  isExplicitInterfaceImplementationWrapper = true;
  DoSomething(): string {
    return this.instance.DoSomething_ExplicitImplementationOfIExplicitInterface();
  }
}

result-matching ""

    No results matching ""