Comparing version 0.0.10 to 0.0.11
@@ -6,5 +6,4 @@ import BaseDefinition from "../definitions/BaseDefinition"; | ||
private readonly factory; | ||
private value; | ||
constructor(factory: Factory); | ||
resolve: <T>(container: IDIContainer) => T; | ||
} |
@@ -25,7 +25,3 @@ "use strict"; | ||
_this.resolve = function (container) { | ||
if (_this.value !== undefined) { | ||
return _this.value; | ||
} | ||
_this.value = _this.factory(container); | ||
return _this.value; | ||
return _this.factory(container); | ||
}; | ||
@@ -32,0 +28,0 @@ _this.factory = factory; |
@@ -11,2 +11,3 @@ import { IDefinition } from "./definitions/IDefinition"; | ||
private definitions; | ||
private resolved; | ||
get<T>(name: string): T; | ||
@@ -13,0 +14,0 @@ addDefinition(name: DefinitionName, definition: IDefinition): void; |
@@ -21,2 +21,3 @@ "use strict"; | ||
this.definitions = {}; | ||
this.resolved = {}; | ||
} | ||
@@ -27,4 +28,8 @@ DIContainer.prototype.get = function (name) { | ||
} | ||
if (this.resolved[name] !== undefined) { | ||
return this.resolved[name]; | ||
} | ||
var definition = this.definitions[name]; | ||
return definition.resolve(this); | ||
this.resolved[name] = definition.resolve(this); | ||
return this.resolved[name]; | ||
}; | ||
@@ -31,0 +36,0 @@ DIContainer.prototype.addDefinition = function (name, definition) { |
{ | ||
"name": "rsdi", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "dependency injection container", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -21,4 +21,2 @@ # RSDI - Dependency Injection Container | ||
function configureHistory(container: IDIContainer): History { | ||
// this factory will be called only once, during first resolving | ||
// then resolved version will be returned | ||
const history = createBrowserHistory(); | ||
@@ -37,7 +35,7 @@ const env = container.get("ENV"); | ||
const history = container.get<History>("BrowserHistory"); // History singleton will be returned | ||
``` | ||
**All definitions are resolved once and their result is kept during the life of the container.** | ||
``` | ||
## Motivation | ||
@@ -44,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23029
362
56