ts-ioc-container 27.2.0 → 27.3.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 +11 -13
- package/cjm/registration/IRegistration.js +2 -2
- package/cjm/registration/Registration.js +1 -1
- package/esm/registration/IRegistration.js +2 -2
- package/esm/registration/Registration.js +1 -1
- package/package.json +2 -2
- package/typings/registration/IRegistration.d.ts +2 -2
- package/typings/registration/Registration.d.ts +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,7 @@ describe('Basic usage', function () {
|
|
|
99
99
|
constructor(@inject(by.key('ILogger')) public logger: Logger) {}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).
|
|
102
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).to('ILogger'));
|
|
103
103
|
|
|
104
104
|
expect(container.resolve(App).logger.name).toBe('Logger');
|
|
105
105
|
});
|
|
@@ -110,8 +110,8 @@ describe('Basic usage', function () {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
const container = new Container(new ReflectionInjector())
|
|
113
|
-
.use(Registration.fromClass(Logger).
|
|
114
|
-
.use(Registration.fromClass(Logger).
|
|
113
|
+
.use(Registration.fromClass(Logger).to('ILogger1'))
|
|
114
|
+
.use(Registration.fromClass(Logger).to('ILogger2'));
|
|
115
115
|
|
|
116
116
|
expect(container.resolve(App).loggers).toHaveLength(2);
|
|
117
117
|
});
|
|
@@ -130,9 +130,7 @@ describe('Basic usage', function () {
|
|
|
130
130
|
|
|
131
131
|
it('should not raise an error when key is busy', () => {
|
|
132
132
|
expect(() => {
|
|
133
|
-
new Container(new ReflectionInjector())
|
|
134
|
-
.use(Registration.fromClass(Logger).assignTo('ILogger'))
|
|
135
|
-
.use(Registration.fromClass(Logger).assignTo('ILogger'));
|
|
133
|
+
new Container(new ReflectionInjector()).use(Registration.fromClass(Logger)).use(Registration.fromClass(Logger));
|
|
136
134
|
}).not.toThrowError(RegistrationConflictError);
|
|
137
135
|
});
|
|
138
136
|
|
|
@@ -286,7 +284,7 @@ class Logger {}
|
|
|
286
284
|
describe('Disposing', function () {
|
|
287
285
|
it('should container and make it unavailable for the further usage', function () {
|
|
288
286
|
const root = new Container(new ReflectionInjector(), { tags: ['root'] }).use(
|
|
289
|
-
Registration.fromClass(Logger).
|
|
287
|
+
Registration.fromClass(Logger).to('ILogger'),
|
|
290
288
|
);
|
|
291
289
|
const child = root.createScope('child');
|
|
292
290
|
|
|
@@ -333,7 +331,7 @@ class App {
|
|
|
333
331
|
|
|
334
332
|
describe('Reflection Injector', function () {
|
|
335
333
|
it('should inject dependencies by @inject decorator', function () {
|
|
336
|
-
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).
|
|
334
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).to('ILogger'));
|
|
337
335
|
|
|
338
336
|
const app = container.resolve(App);
|
|
339
337
|
|
|
@@ -356,7 +354,7 @@ describe('SimpleInjector', function () {
|
|
|
356
354
|
constructor(public container: IContainer) {}
|
|
357
355
|
}
|
|
358
356
|
|
|
359
|
-
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).
|
|
357
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).to('App'));
|
|
360
358
|
const app = container.resolve<App>('App');
|
|
361
359
|
|
|
362
360
|
expect(app.container).toBeInstanceOf(Container);
|
|
@@ -367,7 +365,7 @@ describe('SimpleInjector', function () {
|
|
|
367
365
|
constructor(container: IContainer, public greeting: string) {}
|
|
368
366
|
}
|
|
369
367
|
|
|
370
|
-
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).
|
|
368
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).to('App'));
|
|
371
369
|
const app = container.resolve<App>('App', 'Hello world');
|
|
372
370
|
|
|
373
371
|
expect(app.greeting).toBe('Hello world');
|
|
@@ -395,7 +393,7 @@ describe('ProxyInjector', function () {
|
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
395
|
|
|
398
|
-
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).
|
|
396
|
+
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).to('logger'));
|
|
399
397
|
|
|
400
398
|
const app = container.resolve(App);
|
|
401
399
|
expect(app.logger).toBeInstanceOf(Logger);
|
|
@@ -425,8 +423,8 @@ describe('ProxyInjector', function () {
|
|
|
425
423
|
const greetingTemplate = (name: string) => `Hello ${name}`;
|
|
426
424
|
|
|
427
425
|
const container = new Container(new ProxyInjector())
|
|
428
|
-
.use(Registration.fromClass(App).
|
|
429
|
-
.use(Registration.fromClass(Logger).
|
|
426
|
+
.use(Registration.fromClass(App).to('App').pipe(args({ greetingTemplate })))
|
|
427
|
+
.use(Registration.fromClass(Logger).to('logger'));
|
|
430
428
|
|
|
431
429
|
const app = container.resolve<App>('App', { name: `world` });
|
|
432
430
|
expect(app.greeting).toBe('Hello world');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.3.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": "68462d7b245697342b3250124d4a668c6641fccf"
|
|
64
64
|
}
|
|
@@ -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
|
+
to(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
|
+
to(key: DependencyKey): this;
|
|
14
14
|
pipe(...mappers: MapFn<IProvider>[]): this;
|
|
15
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
|
+
to(key: DependencyKey): this;
|
|
14
14
|
throwErrorOnConflict(): ThrowErrorIfNoDependency;
|
|
15
15
|
pipe(...mappers: MapFn<IProvider>[]): this;
|
|
16
16
|
applyTo(container: IContainer): void;
|