Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ctor error and fix no svc create instance #34

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aster-js/ioc",
"version": "1.7.0",
"version": "1.7.1",
"description": "Aster core library part of Aster js library",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand All @@ -26,11 +26,11 @@
"license": "ISC",
"dependencies": {
"tslib": "^2.6.2",
"@aster-js/core": "^1.3.1",
"@aster-js/core": "^1.3.2",
"@aster-js/async": "^1.4.1",
"@aster-js/decorators": "^1.1.0",
"@aster-js/collections": "^1.0.3",
"@aster-js/iterators": "^1.2.2",
"@aster-js/collections": "^1.0.5",
"@aster-js/iterators": "^1.2.3",
"@aster-js/events": "^1.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/ioc-module/ioc-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export abstract class IoCContainer extends DisposableHost implements IIoCModule
try {
const asyncTasks = [];

this.logger?.debug("Starting IoC module with {setupCount} setups and {serviceCount}", setups.length, this.services.size);
this.logger?.debug("Starting IoC module with {setupCount} setup(s) and {serviceCount} service(s)", setups.length, this.services.size);

for (; idx < setups.length; idx++) {
const setup = setups[idx];
Expand Down
2 changes: 1 addition & 1 deletion src/service-provider/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ServiceProvider implements IServiceProvider, IDisposable {

private *resolveArgs(ctor: Constructor, baseArgs: readonly any[]): Iterable<any> {
const dependencies = [...this._dependencyResolver.resolveDependencies(ctor)];
if (!dependencies.length) return baseArgs;
if (!dependencies.length) return yield* baseArgs;

const [first] = dependencies;
if (baseArgs.length !== first.param.index) {
Expand Down
17 changes: 16 additions & 1 deletion src/service-registry/service-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ export class ServiceRegistry {

*dependencies(ctor: Constructor): Iterable<DependencyParameter> {
const deps = this._dependencies.get(ctor);
if (deps) yield* deps.sort((l, r) => l.index - r.index);
if (deps) {
let nextIdx = -1;
for (const dep of deps.sort((l, r) => l.index - r.index)) {
if (nextIdx === -1) { // First service
nextIdx = dep.index;
}
else if(nextIdx !== dep.index) {
throw new Error(
`Invalid parameter order in constructor of ${ctor.name} at index ${dep.index}.` +
`Dynamic parameters must be first in the constructor.`
);
}
yield dep;
nextIdx++;
}
}
}

get(tag: string | symbol | Constructor): ServiceIdentifier | null {
Expand Down
Loading