added header and test

This commit is contained in:
remojansen
2015-04-18 11:17:20 +01:00
parent 20d6106860
commit a82f4781a1
3 changed files with 109 additions and 48 deletions

View File

@@ -1,13 +0,0 @@
interface TypeBindingInterface<TServiceType> {
runtimeIdentifier : string;
implementationType : { new(): TServiceType ;};
cache : TServiceType;
scope : number; // TypeBindingScopeEnum
}
interface KernelInterface {
bind(typeBinding : TypeBindingInterface<any>) : void;
unbind(runtimeIdentifier : string) : void;
unbindAll() : void;
resolve<TImplementationType>(runtimeIdentifier : string) : TImplementationType;
}

View File

@@ -0,0 +1,75 @@
/// <reference path="inversify.d.ts" />
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<FooInterface>(fooRuntimeIdentifier, Foo);
var barBinding = new inversify.TypeBinding<BarInterface>(barRuntimeIdentifier, Bar);
var fooBarBinding = new inversify.TypeBinding<FooBarInterface>(fooBarRuntimeIdentifier, FooBar);
kernel.bind(fooBinding);
kernel.bind(barBinding);
kernel.bind(fooBarBinding);
// Resolve
var foo = kernel.resolve<Foo>(fooRuntimeIdentifier);
var bar = kernel.resolve<Foo>(barRuntimeIdentifier);
var fooBar = kernel.resolve<Foo>(fooBarRuntimeIdentifier);
// Unbind
kernel.unbind(fooRuntimeIdentifier);
kernel.unbindAll();

View File

@@ -1,37 +1,36 @@
/// <reference path="interfaces.d.ts" />
// Type definitions for inversify 1.0.0
// Project: https://github.com/inversify/InversifyJS
// Definitions by: inversify <https://github.com/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<TServiceType> implements TypeBindingInterface<TServiceType> {
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<any>): void;
unbind(runtimeIdentifier: string): void;
unbindAll(): void;
resolve<TImplementationType>(runtimeIdentifier: string): TImplementationType;
private _validateBinding(typeBinding);
private _getConstructorArguments(func);
private _injectDependencies<TImplementationType>(func);
private _construct<TImplementationType>(constr, args);
constructor();
}
}
declare class TypeBinding<TServiceType> implements TypeBindingInterface<TServiceType> {
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<any>): void;
unbind(runtimeIdentifier: string): void;
unbindAll(): void;
resolve<TImplementationType>(runtimeIdentifier: string): TImplementationType;
private _validateBinding(typeBinding);
private _getConstructorArguments(func);
private _injectDependencies<TImplementationType>(func);
private _construct<TImplementationType>(constr, args);
constructor();
}
declare var inversify: {
Kernel: typeof Kernel;
TypeBindingScopeEnum: typeof TypeBindingScopeEnum;
TypeBinding: typeof TypeBinding;
};