From a82f4781a17d327b7c314244c4b75dc085856029 Mon Sep 17 00:00:00 2001 From: remojansen Date: Sat, 18 Apr 2015 11:17:20 +0100 Subject: [PATCH] added header and test --- inversify/interfaces.d.ts | 13 ------- inversify/inversify-test.ts | 75 +++++++++++++++++++++++++++++++++++++ inversify/inversify.d.ts | 69 +++++++++++++++++----------------- 3 files changed, 109 insertions(+), 48 deletions(-) delete mode 100644 inversify/interfaces.d.ts create mode 100644 inversify/inversify-test.ts diff --git a/inversify/interfaces.d.ts b/inversify/interfaces.d.ts deleted file mode 100644 index eeaa14faf..000000000 --- a/inversify/interfaces.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -interface TypeBindingInterface { - runtimeIdentifier : string; - implementationType : { new(): TServiceType ;}; - cache : TServiceType; - scope : number; // TypeBindingScopeEnum -} - -interface KernelInterface { - bind(typeBinding : TypeBindingInterface) : void; - unbind(runtimeIdentifier : string) : void; - unbindAll() : void; - resolve(runtimeIdentifier : string) : TImplementationType; -} diff --git a/inversify/inversify-test.ts b/inversify/inversify-test.ts new file mode 100644 index 000000000..ffd3394f8 --- /dev/null +++ b/inversify/inversify-test.ts @@ -0,0 +1,75 @@ +/// + +interface FooInterface { + name : string; + greet() : string; +} + +interface BarInterface { + name : string; + greet() : string; +} + +interface FooBarInterface { + foo : FooInterface; + bar : BarInterface; + greet() : string; +} + +export class Foo implements FooInterface { + public name : string; + constructor() { + this.name = "foo"; + } + public greet() : string { + return this.name; + } +} + +class Bar implements BarInterface { + public name : string; + constructor() { + this.name = "bar"; + } + public greet() : string { + return this.name; + } +} + +class FooBar implements FooBarInterface { + public foo : FooInterface; + public bar : BarInterface; + constructor(FooInterface : FooInterface, BarInterface : BarInterface) { + this.foo = FooInterface; + this.bar = BarInterface; + } + public greet() : string{ + return this.foo.greet() + this.bar.greet(); + } +} + +// Kernel +var kernel = new inversify.Kernel(); + +// Identifiers +var fooRuntimeIdentifier = "FooInterface"; +var barRuntimeIdentifier = "BarInterface"; +var fooBarRuntimeIdentifier = "FooBarInterface"; + +// Bindings +var fooBinding = new inversify.TypeBinding(fooRuntimeIdentifier, Foo); +var barBinding = new inversify.TypeBinding(barRuntimeIdentifier, Bar); +var fooBarBinding = new inversify.TypeBinding(fooBarRuntimeIdentifier, FooBar); + +kernel.bind(fooBinding); +kernel.bind(barBinding); +kernel.bind(fooBarBinding); + +// Resolve +var foo = kernel.resolve(fooRuntimeIdentifier); +var bar = kernel.resolve(barRuntimeIdentifier); +var fooBar = kernel.resolve(fooBarRuntimeIdentifier); + +// Unbind +kernel.unbind(fooRuntimeIdentifier); +kernel.unbindAll(); diff --git a/inversify/inversify.d.ts b/inversify/inversify.d.ts index 9c0405298..45f898926 100644 --- a/inversify/inversify.d.ts +++ b/inversify/inversify.d.ts @@ -1,37 +1,36 @@ -/// +// Type definitions for inversify 1.0.0 +// Project: https://github.com/inversify/InversifyJS +// Definitions by: inversify +// Definitions: https://github.com/borisyankov/DefinitelyTyped -declare enum TypeBindingScopeEnum { - Transient = 0, - Singleton = 1, +declare module inversify { + enum TypeBindingScopeEnum { + Transient = 0, + Singleton = 1, + } + + class TypeBinding implements TypeBindingInterface { + runtimeIdentifier: string; + implementationType: { + new (): TServiceType; + }; + cache: TServiceType; + scope: TypeBindingScopeEnum; + constructor(runtimeIdentifier: string, implementationType: { + new (...args: any[]): TServiceType; + }, scopeType?: TypeBindingScopeEnum); + } + + class Kernel implements KernelInterface { + private _bindings; + bind(typeBinding: TypeBindingInterface): void; + unbind(runtimeIdentifier: string): void; + unbindAll(): void; + resolve(runtimeIdentifier: string): TImplementationType; + private _validateBinding(typeBinding); + private _getConstructorArguments(func); + private _injectDependencies(func); + private _construct(constr, args); + constructor(); + } } - -declare class TypeBinding implements TypeBindingInterface { - runtimeIdentifier: string; - implementationType: { - new (): TServiceType; - }; - cache: TServiceType; - scope: TypeBindingScopeEnum; - constructor(runtimeIdentifier: string, implementationType: { - new (...args: any[]): TServiceType; - }, scopeType?: TypeBindingScopeEnum); -} - -declare class Kernel implements KernelInterface { - private _bindings; - bind(typeBinding: TypeBindingInterface): void; - unbind(runtimeIdentifier: string): void; - unbindAll(): void; - resolve(runtimeIdentifier: string): TImplementationType; - private _validateBinding(typeBinding); - private _getConstructorArguments(func); - private _injectDependencies(func); - private _construct(constr, args); - constructor(); -} - -declare var inversify: { - Kernel: typeof Kernel; - TypeBindingScopeEnum: typeof TypeBindingScopeEnum; - TypeBinding: typeof TypeBinding; -};