-
Notifications
You must be signed in to change notification settings - Fork 0
Class with custom instance implementation ๐
Damiรกn Pumar edited this page Dec 22, 2023
·
2 revisions
export interface Interface {
doSomething(): string;
}
export class InterfaceImplementation implements Interface {
doSomething(): string {
return "HI";
}
}
export class ClassWithInterfaceDependency {
constructor(private readonly dependency: Interface) {}
doSomething(): string {
return this.dependency.doSomething();
}
}
Container.register([
register("Interface").withImplementation(InterfaceImplementation).build(),
register(ClassWithInterfaceDependency).withDependency("Interface").build(),
]);
const resolved = Container.resolve(ClassWithInterfaceDependency);
expect(resolved.doSomething()).toBe("HI");