ts-ioc-container 27.1.2 → 27.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -19
- package/cjm/container/EmptyContainer.js +2 -2
- package/cjm/registration/IRegistration.js +4 -4
- package/cjm/registration/Registration.js +1 -1
- package/esm/container/EmptyContainer.js +2 -2
- package/esm/registration/IRegistration.js +4 -4
- package/esm/registration/Registration.js +1 -1
- package/package.json +2 -2
- package/typings/container/EmptyContainer.d.ts +3 -3
- package/typings/container/IContainer.d.ts +1 -1
- package/typings/registration/IRegistration.d.ts +3 -3
- package/typings/registration/Registration.d.ts +1 -1
package/README.md
CHANGED
|
@@ -84,7 +84,6 @@ import {
|
|
|
84
84
|
Container,
|
|
85
85
|
inject,
|
|
86
86
|
ReflectionInjector,
|
|
87
|
-
Provider,
|
|
88
87
|
RegistrationConflictError,
|
|
89
88
|
Registration,
|
|
90
89
|
key,
|
|
@@ -100,7 +99,7 @@ describe('Basic usage', function () {
|
|
|
100
99
|
constructor(@inject(by.key('ILogger')) public logger: Logger) {}
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
const container = new Container(new ReflectionInjector()).
|
|
102
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).assignTo('ILogger'));
|
|
104
103
|
|
|
105
104
|
expect(container.resolve(App).logger.name).toBe('Logger');
|
|
106
105
|
});
|
|
@@ -111,8 +110,8 @@ describe('Basic usage', function () {
|
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
const container = new Container(new ReflectionInjector())
|
|
114
|
-
.
|
|
115
|
-
.
|
|
113
|
+
.use(Registration.fromClass(Logger).assignTo('ILogger1'))
|
|
114
|
+
.use(Registration.fromClass(Logger).assignTo('ILogger2'));
|
|
116
115
|
|
|
117
116
|
expect(container.resolve(App).loggers).toHaveLength(2);
|
|
118
117
|
});
|
|
@@ -132,8 +131,8 @@ describe('Basic usage', function () {
|
|
|
132
131
|
it('should not raise an error when key is busy', () => {
|
|
133
132
|
expect(() => {
|
|
134
133
|
new Container(new ReflectionInjector())
|
|
135
|
-
.
|
|
136
|
-
.
|
|
134
|
+
.use(Registration.fromClass(Logger).assignTo('ILogger'))
|
|
135
|
+
.use(Registration.fromClass(Logger).assignTo('ILogger'));
|
|
137
136
|
}).not.toThrowError(RegistrationConflictError);
|
|
138
137
|
});
|
|
139
138
|
|
|
@@ -280,15 +279,14 @@ Sometimes you want to dispose container and all its scopes. For example, when yo
|
|
|
280
279
|
|
|
281
280
|
```typescript
|
|
282
281
|
import 'reflect-metadata';
|
|
283
|
-
import { Container, ContainerDisposedError,
|
|
282
|
+
import { Container, ContainerDisposedError, ReflectionInjector, Registration } from 'ts-ioc-container';
|
|
284
283
|
|
|
285
284
|
class Logger {}
|
|
286
285
|
|
|
287
286
|
describe('Disposing', function () {
|
|
288
287
|
it('should container and make it unavailable for the further usage', function () {
|
|
289
|
-
const root = new Container(new ReflectionInjector(), { tags: ['root'] }).
|
|
290
|
-
'ILogger',
|
|
291
|
-
Provider.fromClass(Logger),
|
|
288
|
+
const root = new Container(new ReflectionInjector(), { tags: ['root'] }).use(
|
|
289
|
+
Registration.fromClass(Logger).assignTo('ILogger'),
|
|
292
290
|
);
|
|
293
291
|
const child = root.createScope('child');
|
|
294
292
|
|
|
@@ -315,7 +313,7 @@ This type of injector uses `@inject` decorator to mark where dependencies should
|
|
|
315
313
|
|
|
316
314
|
```typescript
|
|
317
315
|
import 'reflect-metadata';
|
|
318
|
-
import { by, Container, inject,
|
|
316
|
+
import { by, Container, inject, ReflectionInjector, Registration } from 'ts-ioc-container';
|
|
319
317
|
|
|
320
318
|
class Logger {
|
|
321
319
|
name = 'Logger';
|
|
@@ -335,7 +333,7 @@ class App {
|
|
|
335
333
|
|
|
336
334
|
describe('Reflection Injector', function () {
|
|
337
335
|
it('should inject dependencies by @inject decorator', function () {
|
|
338
|
-
const container = new Container(new ReflectionInjector()).
|
|
336
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).assignTo('ILogger'));
|
|
339
337
|
|
|
340
338
|
const app = container.resolve(App);
|
|
341
339
|
|
|
@@ -350,7 +348,7 @@ This type of injector just passes container to constructor with others arguments
|
|
|
350
348
|
|
|
351
349
|
```typescript
|
|
352
350
|
import 'reflect-metadata';
|
|
353
|
-
import { Container, IContainer,
|
|
351
|
+
import { Container, IContainer, Registration, SimpleInjector } from 'ts-ioc-container';
|
|
354
352
|
|
|
355
353
|
describe('SimpleInjector', function () {
|
|
356
354
|
it('should pass container as first parameter', function () {
|
|
@@ -358,7 +356,7 @@ describe('SimpleInjector', function () {
|
|
|
358
356
|
constructor(public container: IContainer) {}
|
|
359
357
|
}
|
|
360
358
|
|
|
361
|
-
const container = new Container(new SimpleInjector()).
|
|
359
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).assignTo('App'));
|
|
362
360
|
const app = container.resolve<App>('App');
|
|
363
361
|
|
|
364
362
|
expect(app.container).toBeInstanceOf(Container);
|
|
@@ -369,7 +367,7 @@ describe('SimpleInjector', function () {
|
|
|
369
367
|
constructor(container: IContainer, public greeting: string) {}
|
|
370
368
|
}
|
|
371
369
|
|
|
372
|
-
const container = new Container(new SimpleInjector()).
|
|
370
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).assignTo('App'));
|
|
373
371
|
const app = container.resolve<App>('App', 'Hello world');
|
|
374
372
|
|
|
375
373
|
expect(app.greeting).toBe('Hello world');
|
|
@@ -383,7 +381,7 @@ This type of injector injects dependencies as dictionary `Record<string, unknown
|
|
|
383
381
|
|
|
384
382
|
```typescript
|
|
385
383
|
import 'reflect-metadata';
|
|
386
|
-
import { Container,
|
|
384
|
+
import { Container, ProxyInjector, args, Registration } from 'ts-ioc-container';
|
|
387
385
|
|
|
388
386
|
describe('ProxyInjector', function () {
|
|
389
387
|
it('should pass dependency to constructor as dictionary', function () {
|
|
@@ -397,7 +395,7 @@ describe('ProxyInjector', function () {
|
|
|
397
395
|
}
|
|
398
396
|
}
|
|
399
397
|
|
|
400
|
-
const container = new Container(new ProxyInjector()).
|
|
398
|
+
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).assignTo('logger'));
|
|
401
399
|
|
|
402
400
|
const app = container.resolve(App);
|
|
403
401
|
expect(app.logger).toBeInstanceOf(Logger);
|
|
@@ -427,8 +425,8 @@ describe('ProxyInjector', function () {
|
|
|
427
425
|
const greetingTemplate = (name: string) => `Hello ${name}`;
|
|
428
426
|
|
|
429
427
|
const container = new Container(new ProxyInjector())
|
|
430
|
-
.
|
|
431
|
-
.
|
|
428
|
+
.use(Registration.fromClass(App).assignTo('App').pipe(args({ greetingTemplate })))
|
|
429
|
+
.use(Registration.fromClass(Logger).assignTo('logger'));
|
|
432
430
|
|
|
433
431
|
const app = container.resolve<App>('App', { name: `world` });
|
|
434
432
|
expect(app.greeting).toBe('Hello world');
|
|
@@ -19,7 +19,7 @@ class EmptyContainer {
|
|
|
19
19
|
dispose() {
|
|
20
20
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
21
21
|
}
|
|
22
|
-
register() {
|
|
22
|
+
register(key, value) {
|
|
23
23
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
24
24
|
}
|
|
25
25
|
resolve(key) {
|
|
@@ -32,7 +32,7 @@ class EmptyContainer {
|
|
|
32
32
|
return [];
|
|
33
33
|
}
|
|
34
34
|
removeScope() { }
|
|
35
|
-
use() {
|
|
35
|
+
use(module) {
|
|
36
36
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -8,16 +8,16 @@ class RegistrationDecorator {
|
|
|
8
8
|
getKey() {
|
|
9
9
|
return this.decorated.getKey();
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
this.decorated.
|
|
11
|
+
assignTo(key) {
|
|
12
|
+
this.decorated.assignTo(key);
|
|
13
13
|
return this;
|
|
14
14
|
}
|
|
15
15
|
pipe(...mappers) {
|
|
16
16
|
this.decorated.pipe(...mappers);
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
|
-
applyTo(container
|
|
20
|
-
this.decorated.applyTo(container
|
|
19
|
+
applyTo(container) {
|
|
20
|
+
this.decorated.applyTo(container);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.RegistrationDecorator = RegistrationDecorator;
|
|
@@ -16,7 +16,7 @@ export class EmptyContainer {
|
|
|
16
16
|
dispose() {
|
|
17
17
|
throw new MethodNotImplementedError();
|
|
18
18
|
}
|
|
19
|
-
register() {
|
|
19
|
+
register(key, value) {
|
|
20
20
|
throw new MethodNotImplementedError();
|
|
21
21
|
}
|
|
22
22
|
resolve(key) {
|
|
@@ -29,7 +29,7 @@ export class EmptyContainer {
|
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
31
31
|
removeScope() { }
|
|
32
|
-
use() {
|
|
32
|
+
use(module) {
|
|
33
33
|
throw new MethodNotImplementedError();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -5,15 +5,15 @@ export class RegistrationDecorator {
|
|
|
5
5
|
getKey() {
|
|
6
6
|
return this.decorated.getKey();
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
this.decorated.
|
|
8
|
+
assignTo(key) {
|
|
9
|
+
this.decorated.assignTo(key);
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
12
|
pipe(...mappers) {
|
|
13
13
|
this.decorated.pipe(...mappers);
|
|
14
14
|
return this;
|
|
15
15
|
}
|
|
16
|
-
applyTo(container
|
|
17
|
-
this.decorated.applyTo(container
|
|
16
|
+
applyTo(container) {
|
|
17
|
+
this.decorated.applyTo(container);
|
|
18
18
|
}
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.2.0",
|
|
4
4
|
"description": "Typescript IoC container",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"ts-node": "^10.9.1",
|
|
61
61
|
"typescript": "4.4.3"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "24f9e47646271367a7a000814c6fc4f7470d3bf5"
|
|
64
64
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DependencyKey, IContainer, InjectionToken } from './IContainer';
|
|
1
|
+
import { DependencyKey, IContainer, IContainerModule, InjectionToken } from './IContainer';
|
|
2
2
|
import { IProvider } from '../provider/IProvider';
|
|
3
3
|
export declare class EmptyContainer implements IContainer {
|
|
4
4
|
hasDependency(key: string): boolean;
|
|
@@ -6,10 +6,10 @@ export declare class EmptyContainer implements IContainer {
|
|
|
6
6
|
hasTag(): boolean;
|
|
7
7
|
createScope(): IContainer;
|
|
8
8
|
dispose(): void;
|
|
9
|
-
register(): this;
|
|
9
|
+
register(key: DependencyKey, value: IProvider): this;
|
|
10
10
|
resolve<T>(key: InjectionToken<T>): T;
|
|
11
11
|
getAllProviders(): Map<DependencyKey, IProvider>;
|
|
12
12
|
getInstances(): unknown[];
|
|
13
13
|
removeScope(): void;
|
|
14
|
-
use(): this;
|
|
14
|
+
use(module: IContainerModule): this;
|
|
15
15
|
}
|
|
@@ -12,7 +12,7 @@ export interface Resolvable {
|
|
|
12
12
|
resolve<T>(key: InjectionToken<T>, ...args: unknown[]): T;
|
|
13
13
|
}
|
|
14
14
|
export interface IContainerModule {
|
|
15
|
-
applyTo(container: IContainer
|
|
15
|
+
applyTo(container: IContainer): void;
|
|
16
16
|
}
|
|
17
17
|
export interface IRegistrationOptions {
|
|
18
18
|
override?: boolean;
|
|
@@ -3,14 +3,14 @@ import { MapFn } from '../utils';
|
|
|
3
3
|
import { IProvider } from '../provider/IProvider';
|
|
4
4
|
export interface IRegistration extends IContainerModule {
|
|
5
5
|
getKey(): DependencyKey;
|
|
6
|
-
|
|
6
|
+
assignTo(key: DependencyKey): this;
|
|
7
7
|
pipe(...mappers: MapFn<IProvider>[]): this;
|
|
8
8
|
}
|
|
9
9
|
export declare abstract class RegistrationDecorator implements IRegistration {
|
|
10
10
|
private decorated;
|
|
11
11
|
constructor(decorated: IRegistration);
|
|
12
12
|
getKey(): DependencyKey;
|
|
13
|
-
|
|
13
|
+
assignTo(key: DependencyKey): this;
|
|
14
14
|
pipe(...mappers: MapFn<IProvider>[]): this;
|
|
15
|
-
applyTo(container: IContainer
|
|
15
|
+
applyTo(container: IContainer): void;
|
|
16
16
|
}
|
|
@@ -10,7 +10,7 @@ export declare class Registration implements IRegistration {
|
|
|
10
10
|
static fromClass(Target: constructor<unknown>): Registration;
|
|
11
11
|
constructor(key: DependencyKey, provider: IProvider);
|
|
12
12
|
getKey(): DependencyKey;
|
|
13
|
-
|
|
13
|
+
assignTo(key: DependencyKey): this;
|
|
14
14
|
throwErrorOnConflict(): ThrowErrorIfNoDependency;
|
|
15
15
|
pipe(...mappers: MapFn<IProvider>[]): this;
|
|
16
16
|
applyTo(container: IContainer): void;
|