ts-ioc-container 27.2.1 → 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 +10 -10
- 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
|
});
|
|
@@ -284,7 +284,7 @@ class Logger {}
|
|
|
284
284
|
describe('Disposing', function () {
|
|
285
285
|
it('should container and make it unavailable for the further usage', function () {
|
|
286
286
|
const root = new Container(new ReflectionInjector(), { tags: ['root'] }).use(
|
|
287
|
-
Registration.fromClass(Logger).
|
|
287
|
+
Registration.fromClass(Logger).to('ILogger'),
|
|
288
288
|
);
|
|
289
289
|
const child = root.createScope('child');
|
|
290
290
|
|
|
@@ -331,7 +331,7 @@ class App {
|
|
|
331
331
|
|
|
332
332
|
describe('Reflection Injector', function () {
|
|
333
333
|
it('should inject dependencies by @inject decorator', function () {
|
|
334
|
-
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).
|
|
334
|
+
const container = new Container(new ReflectionInjector()).use(Registration.fromClass(Logger).to('ILogger'));
|
|
335
335
|
|
|
336
336
|
const app = container.resolve(App);
|
|
337
337
|
|
|
@@ -354,7 +354,7 @@ describe('SimpleInjector', function () {
|
|
|
354
354
|
constructor(public container: IContainer) {}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).
|
|
357
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).to('App'));
|
|
358
358
|
const app = container.resolve<App>('App');
|
|
359
359
|
|
|
360
360
|
expect(app.container).toBeInstanceOf(Container);
|
|
@@ -365,7 +365,7 @@ describe('SimpleInjector', function () {
|
|
|
365
365
|
constructor(container: IContainer, public greeting: string) {}
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
-
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).
|
|
368
|
+
const container = new Container(new SimpleInjector()).use(Registration.fromClass(App).to('App'));
|
|
369
369
|
const app = container.resolve<App>('App', 'Hello world');
|
|
370
370
|
|
|
371
371
|
expect(app.greeting).toBe('Hello world');
|
|
@@ -393,7 +393,7 @@ describe('ProxyInjector', function () {
|
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
|
|
396
|
-
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).
|
|
396
|
+
const container = new Container(new ProxyInjector()).use(Registration.fromClass(Logger).to('logger'));
|
|
397
397
|
|
|
398
398
|
const app = container.resolve(App);
|
|
399
399
|
expect(app.logger).toBeInstanceOf(Logger);
|
|
@@ -423,8 +423,8 @@ describe('ProxyInjector', function () {
|
|
|
423
423
|
const greetingTemplate = (name: string) => `Hello ${name}`;
|
|
424
424
|
|
|
425
425
|
const container = new Container(new ProxyInjector())
|
|
426
|
-
.use(Registration.fromClass(App).
|
|
427
|
-
.use(Registration.fromClass(Logger).
|
|
426
|
+
.use(Registration.fromClass(App).to('App').pipe(args({ greetingTemplate })))
|
|
427
|
+
.use(Registration.fromClass(Logger).to('logger'));
|
|
428
428
|
|
|
429
429
|
const app = container.resolve<App>('App', { name: `world` });
|
|
430
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;
|