mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
added header and test
This commit is contained in:
13
inversify/interfaces.d.ts
vendored
13
inversify/interfaces.d.ts
vendored
@@ -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;
|
||||
}
|
||||
75
inversify/inversify-test.ts
Normal file
75
inversify/inversify-test.ts
Normal 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();
|
||||
69
inversify/inversify.d.ts
vendored
69
inversify/inversify.d.ts
vendored
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user