Skip to content

Commit 67843a4

Browse files
authored
Merge pull request #40 from indigotech/feature/use-container
Feature - @UseContainer deprecation
2 parents 45319f5 + 0e9acd2 commit 67843a4

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## master
2+
3+
- (breaking change) `useContainer` is now a function instead of a decorator - #40
4+
15
## 0.8.0
26

37
### Feature

src/decorator/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './union-type.decorator';
33
export * from './object-type.decorator';
44
export * from './entry-type.decorator';
55
export * from './schema.decorator';
6-
export * from './use-container.decorator';
76
export * from './arg.decorator';
87
export * from './context.decorator';
98
export * from './field.decorator';

src/decorator/use-container.decorator.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './pagination.type';
77
export * from './decorator/';
88
export * from './metadata/options';
99
export * from './middleware';
10+
export * from './use-container';

src/specs/functional.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import 'reflect-metadata';
33
import * as D from '../decorator';
44
import * as graphql from 'graphql';
55

6+
import { IoCContainer } from '../ioc-container';
67
import { schemaFactory } from '../type-factory';
8+
import { useContainer } from '../use-container';
79

810
const assert = require('assert');
911

@@ -235,4 +237,19 @@ describe('Functional', function () {
235237
});
236238

237239
});
240+
241+
describe('useContainer', function() {
242+
243+
afterEach(function() {
244+
delete IoCContainer.INSTANCE;
245+
});
246+
247+
it('sets the DI container properly', function() {
248+
249+
const container = {};
250+
useContainer(container);
251+
assert(IoCContainer.INSTANCE === container);
252+
});
253+
254+
});
238255
});

src/use-container.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { IoCContainer } from './ioc-container';
2+
3+
/**
4+
* Sets the IoC container to be used in order to instantiate the decorated classes
5+
* @param container A [typedi]{@link https://github.com/pleerock/typedi} container
6+
*/
7+
export function useContainer(container: any): void {
8+
IoCContainer.INSTANCE = container;
9+
}

0 commit comments

Comments
 (0)