ts-ioc-container 27.1.2 → 27.2.1
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 +16 -20
- 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
|
});
|
|
@@ -131,9 +130,7 @@ describe('Basic usage', function () {
|
|
|
131
130
|
|
|
132
131
|
it('should not raise an error when key is busy', () => {
|
|
133
132
|
expect(() => {
|
|
134
|
-
new Container(new ReflectionInjector())
|
|
135
|
-
.register('ILogger', Provider.fromClass(Logger))
|
|
136
|
-
.register('ILogger', Provider.fromClass(Logger));
|
|
133
|
+
new Container(new ReflectionInjector()).use(Registration.fromClass(Logger)).use(Registration.fromClass(Logger));
|
|
137
134
|
}).not.toThrowError(RegistrationConflictError);
|
|
138
135
|
});
|
|
139
136
|
|
|
@@ -280,15 +277,14 @@ Sometimes you want to dispose container and all its scopes. For example, when yo
|
|
|
280
277
|
|
|
281
278
|
```typescript
|
|
282
279
|
import 'reflect-metadata';
|
|
283
|
-
import { Container, ContainerDisposedError,
|
|
280
|
+
import { Container, ContainerDisposedError, ReflectionInjector, Registration } from 'ts-ioc-container';
|
|
284
281
|
|
|
285
282
|
class Logger {}
|
|
286
283
|
|
|
287
284
|
describe('Disposing', function () {
|
|
288
285
|
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),
|
|
286
|
+
const root = new Container(new ReflectionInjector(), { tags: ['root'] }).use(
|
|
287
|
+
Registration.fromClass(Logger).assignTo('ILogger'),
|
|
292
288
|
);
|
|
293
289
|
const child = root.createScope('child');
|
|
294
290
|
|
|
@@ -315,7 +311,7 @@ This type of injector uses `@inject` decorator to mark where dependencies should
|
|
|
315
311
|
|
|
316
312
|
```typescript
|
|
317
313
|
import 'reflect-metadata';
|
|
318
|
-
import { by, Container, inject,
|
|
314
|
+
import { by, Container, inject, ReflectionInjector, Registration } from 'ts-ioc-container';
|
|
319
315
|
|
|
320
316
|
class Logger {
|
|
321
317
|
name = 'Logger';
|
|
@@ -335,7 +331,7 @@ class App {
|
|
|
335
331
|
|
|
336
332
|
describe('Reflection Injector', function () {
|
|
337
333
|
it('should inject dependencies by @inject decorator', function () {
|
|
338
|
-
const container = new Container(new ReflectionInjector()).
|
|
334
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).assignTo('ILogger'));
|
|
339
335
|
|
|
340
336
|
const app = container.resolve(App);
|
|
341
337
|
|
|
@@ -350,7 +346,7 @@ This type of injector just passes container to constructor with others arguments
|
|
|
350
346
|
|
|
351
347
|
```typescript
|
|
352
348
|
import 'reflect-metadata';
|
|
353
|
-
import { Container, IContainer,
|
|
349
|
+
import { Container, IContainer, Registration, SimpleInjector } from 'ts-ioc-container';
|
|
354
350
|
|
|
355
351
|
describe('SimpleInjector', function () {
|
|
356
352
|
it('should pass container as first parameter', function () {
|
|
@@ -358,7 +354,7 @@ describe('SimpleInjector', function () {
|
|
|
358
354
|
constructor(public container: IContainer) {}
|
|
359
355
|
}
|
|
360
356
|
|
|
361
|
-
const container = new Container(new SimpleInjector()).
|
|
357
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).assignTo('App'));
|
|
362
358
|
const app = container.resolve<App>('App');
|
|
363
359
|
|
|
364
360
|
expect(app.container).toBeInstanceOf(Container);
|
|
@@ -369,7 +365,7 @@ describe('SimpleInjector', function () {
|
|
|
369
365
|
constructor(container: IContainer, public greeting: string) {}
|
|
370
366
|
}
|
|
371
367
|
|
|
372
|
-
const container = new Container(new SimpleInjector()).
|
|
368
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).assignTo('App'));
|
|
373
369
|
const app = container.resolve<App>('App', 'Hello world');
|
|
374
370
|
|
|
375
371
|
expect(app.greeting).toBe('Hello world');
|
|
@@ -383,7 +379,7 @@ This type of injector injects dependencies as dictionary `Record<string, unknown
|
|
|
383
379
|
|
|
384
380
|
```typescript
|
|
385
381
|
import 'reflect-metadata';
|
|
386
|
-
import { Container,
|
|
382
|
+
import { Container, ProxyInjector, args, Registration } from 'ts-ioc-container';
|
|
387
383
|
|
|
388
384
|
describe('ProxyInjector', function () {
|
|
389
385
|
it('should pass dependency to constructor as dictionary', function () {
|
|
@@ -397,7 +393,7 @@ describe('ProxyInjector', function () {
|
|
|
397
393
|
}
|
|
398
394
|
}
|
|
399
395
|
|
|
400
|
-
const container = new Container(new ProxyInjector()).
|
|
396
|
+
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).assignTo('logger'));
|
|
401
397
|
|
|
402
398
|
const app = container.resolve(App);
|
|
403
399
|
expect(app.logger).toBeInstanceOf(Logger);
|
|
@@ -427,8 +423,8 @@ describe('ProxyInjector', function () {
|
|
|
427
423
|
const greetingTemplate = (name: string) => `Hello ${name}`;
|
|
428
424
|
|
|
429
425
|
const container = new Container(new ProxyInjector())
|
|
430
|
-
.
|
|
431
|
-
.
|
|
426
|
+
.use(Registration.fromClass(App).assignTo('App').pipe(args({ greetingTemplate })))
|
|
427
|
+
.use(Registration.fromClass(Logger).assignTo('logger'));
|
|
432
428
|
|
|
433
429
|
const app = container.resolve<App>('App', { name: `world` });
|
|
434
430
|
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.1
|
|
3
|
+
"version": "27.2.1",
|
|
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": "e01a8df7f3eb7ad5563f9f9185c25bbe171e4af7"
|
|
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;
|