Skip to content

Commit e07e54d

Browse files
FIX #3
1 parent 5bbbe8b commit e07e54d

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-ioc",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "A Lightweight annotation-based dependency injection container for typescript.",
55
"author": "Thiago da Rosa de Bustamante <[email protected]>",
66
"dependencies": {

src/typescript-ioc.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,6 @@ function InjectParamDecorator(target: Object, propertyKey: string | symbol,
225225
}
226226
}
227227

228-
/*********************** Container **************************/
229-
class Map<V> {
230-
put(key: any, value: V) {
231-
this[key] = value;
232-
}
233-
234-
get(key: any): V {
235-
return this[key];
236-
}
237-
238-
remove(key: any) {
239-
delete this[key];
240-
}
241-
}
242-
243228
/**
244229
* The IoC Container class. Can be used to register and to retrieve your dependencies.
245230
* You can also use de decorators [[AutoWired]], [[Scoped]], [[Singleton]], [[Provided]] and [[Provides]]
@@ -283,7 +268,7 @@ export class Container {
283268
* Internal implementation of IoC Container.
284269
*/
285270
class IoCContainer {
286-
private static bindings: Map<ConfigImpl> = new Map<ConfigImpl>();
271+
private static bindings: Map<FunctionConstructor,ConfigImpl> = new Map<FunctionConstructor,ConfigImpl>();
287272

288273
static isBound(source: Function): boolean
289274
{
@@ -299,7 +284,7 @@ class IoCContainer {
299284
let config: ConfigImpl = IoCContainer.bindings.get(baseSource);
300285
if (!config) {
301286
config = new ConfigImpl(baseSource);
302-
IoCContainer.bindings.put(baseSource, config);
287+
IoCContainer.bindings.set(baseSource, config);
303288
}
304289
return config;
305290
}
@@ -506,21 +491,21 @@ Scope.Local = new LocalScope();
506491
* Scope that create only a single instace to handle all dependency resolution requests.
507492
*/
508493
class SingletonScope extends Scope {
509-
private static instances: Map<any> = new Map<any>();
494+
private static instances: Map<Function,any> = new Map<Function,any>();
510495

511496
resolve(provider: Provider, source: Function) {
512497
let instance: any = SingletonScope.instances.get(source);
513498
if (!instance) {
514499
source['__block_Instantiation'] = false;
515500
instance = provider.get();
516501
source['__block_Instantiation'] = true;
517-
SingletonScope.instances.put(source, instance);
502+
SingletonScope.instances.set(source, instance);
518503
}
519504
return instance;
520505
}
521506

522507
reset(source: Function) {
523-
SingletonScope.instances.remove(InjectorHanlder.getConstructorFromType(source));
508+
SingletonScope.instances.delete(InjectorHanlder.getConstructorFromType(source));
524509
}
525510
}
526511

@@ -531,7 +516,7 @@ Scope.Singleton = new SingletonScope();
531516
* Utility class to handle injection behavior on class decorations.
532517
*/
533518
class InjectorHanlder {
534-
static typeInjections: Map<Array<any>> = new Map<Array<any>>();
519+
static typeInjections: Map<string,Array<any>> = new Map<string,Array<any>>();
535520

536521
static decorateConstructor(derived: Function, base: Function) {
537522
for (var p in base) {
@@ -583,3 +568,19 @@ class InjectorHanlder {
583568
}
584569
}
585570

571+
interface Map<K, V> {
572+
clear(): void;
573+
delete(key: K): boolean;
574+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
575+
get(key: K): V | undefined;
576+
has(key: K): boolean;
577+
set(key: K, value?: V): this;
578+
readonly size: number;
579+
}
580+
581+
interface MapConstructor {
582+
new (): Map<any, any>;
583+
new <K, V>(entries?: [K, V][]): Map<K, V>;
584+
readonly prototype: Map<any, any>;
585+
}
586+
declare var Map: MapConstructor;

0 commit comments

Comments
 (0)