Skip to content

Commit 88192ff

Browse files
author
Thiago Bustamante
committed
rename OnlyContainerCanInstantiate
1 parent 83cd536 commit 88192ff

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ It can be used on browser, on react native or on node.js server code.
2323
- [Local Scope](#local-scope)
2424
- [Custom Scopes](#custom-scopes)
2525
- [@Factory](#factories)
26-
- [@OnlyContainerCanInstantiate](#the-onlycontainercaninstantiate-annotation)
26+
- [@OnlyInstantiableByContainer](#the-onlyinstantiablebycontainer-annotation)
2727
- [@The Container Class](#the-container-class)
2828
- [Creating temporary configurations](#creating-temporary-configurations)
2929
- [Importing configurations from external file](#importing-configurations-from-external-file)
@@ -251,14 +251,14 @@ class PersonService {
251251
}
252252
```
253253

254-
## The @OnlyContainerCanInstantiate annotation
255-
The @OnlyContainerCanInstantiate annotation transforms the annotated class, changing its constructor. So, it will only be able to create new instances for the decorated class through to the IoC Container.
254+
## The @OnlyInstantiableByContainer annotation
255+
The @OnlyInstantiableByContainer annotation transforms the annotated class, changing its constructor. So, it will only be able to create new instances for the decorated class through to the IoC Container.
256256

257257
It is usefull, for example, to avoid direct instantiation of Singletons.
258258

259259
```typescript
260260
@Singleton
261-
@OnlyContainerCanInstantiate
261+
@OnlyInstantiableByContainer
262262
class PersonService {
263263
@Inject
264264
private personDAO: PersonDAO;
@@ -302,12 +302,12 @@ let otherPersonDAO: PersonDAO = new PersonDAO();
302302
```
303303

304304
```typescript
305-
@OnlyContainerCanInstantiate
305+
@OnlyInstantiableByContainer
306306
@Singleton
307307
class PersonDAO {
308308
}
309309

310-
let p: PersonDAO = new PersonDAO(); // throws a TypeError. classes decorated with @OnlyContainerCanInstantiate can not be instantiated directly
310+
let p: PersonDAO = new PersonDAO(); // throws a TypeError. classes decorated with @OnlyInstantiableByContainer can not be instantiated directly
311311

312312
const personFactory: ObjectFactory = () => new PersonDAO();
313313
Container.bind(PersonDAO).factory(personFactory); //Works OK
@@ -548,9 +548,9 @@ If you need to support es5 code, you can keep using the 1.2.6 version
548548

549549
#### @AutoWired renamed
550550

551-
A lot of confusion with ```@AutoWired``` motivated us to rename it to ```@OnlyContainerCanInstantiate```. It is a big name, but it says exactly what that decorator does. It is completely optional (The container will always work in the same way when instrumenting the types), but it transforms the decorated constructor to avoid that anybody create new instances calling direct a new expression.
551+
A lot of confusion with ```@AutoWired``` motivated us to rename it to ```@OnlyInstantiableByContainer```. It is a big name, but it says exactly what that decorator does. It is completely optional (The container will always work in the same way when instrumenting the types), but it transforms the decorated constructor to avoid that anybody create new instances calling direct a new expression.
552552

553-
So you need to change all references to ```@AutoWired``` to ```@OnlyContainerCanInstantiate```.
553+
So you need to change all references to ```@AutoWired``` to ```@OnlyInstantiableByContainer```.
554554

555555
#### @Provided @Provides and Provider interface removed
556556

src/decorators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function Singleton(target: Function) {
5050
* So, if you write:
5151
*
5252
* ```
53-
* @ OnlyContainerCanInstantiate
53+
* @ OnlyInstantiableByContainer
5454
* class PersonService {
5555
* @ Inject
5656
* personDAO: PersonDAO;
@@ -63,7 +63,7 @@ export function Singleton(target: Function) {
6363
* let PersonService = new PersonService(); // will thrown a TypeError exception
6464
* ```
6565
*/
66-
export function OnlyContainerCanInstantiate(target: Function) {
66+
export function OnlyInstantiableByContainer(target: Function) {
6767
return IoCContainer.bind(target).instrumentConstructor().decoratedConstructor as any;
6868
}
6969

src/typescript-ioc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Scope.Request = new RequestScope();
2121

2222
/**
2323
* The IoC Container class. Can be used to register and to retrieve your dependencies.
24-
* You can also use de decorators [[OnlyContainerCanInstantiate]], [[Scoped]], [[Singleton]], [[Factory]]
24+
* You can also use de decorators [[OnlyInstantiableByContainer]], [[Scoped]], [[Singleton]], [[Factory]]
2525
* to configure the dependency directly on the class.
2626
*/
2727
export class Container {

test/integration/ioc-container-tests.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { Container, Inject, Scoped, Scope, ObjectFactory, Singleton, Factory } from '../../src/typescript-ioc';
3-
import { OnlyContainerCanInstantiate, InRequestScope } from '../../src/decorators';
3+
import { OnlyInstantiableByContainer, InRequestScope } from '../../src/decorators';
44

55
describe('@Inject annotation on a property', () => {
66

@@ -414,9 +414,9 @@ describe('The IoC Container.snapshot(source)', () => {
414414
});
415415
});
416416

417-
describe('@OnlyContainerCanInstantiate decorator', () => {
417+
describe('@OnlyInstantiableByContainer decorator', () => {
418418

419-
@OnlyContainerCanInstantiate
419+
@OnlyInstantiableByContainer
420420
@Singleton
421421
class SingletonInstantiation {
422422
public static countInstances = 0;
@@ -427,7 +427,7 @@ describe('@OnlyContainerCanInstantiate decorator', () => {
427427
}
428428
}
429429

430-
@OnlyContainerCanInstantiate
430+
@OnlyInstantiableByContainer
431431
class LocalInstantiation {
432432
}
433433

test/unit/decorators.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import { IoCContainer } from '../../src/container/container';
33
import { Inject, Config, Singleton, Scope, Scoped, Factory } from '../../src/typescript-ioc';
4-
import { OnlyContainerCanInstantiate } from '../../src/decorators';
4+
import { OnlyInstantiableByContainer } from '../../src/decorators';
55

66
jest.mock('../../src/container/container');
77
const mockInjectProperty = IoCContainer.injectProperty as jest.Mock;
@@ -119,7 +119,7 @@ describe('@Factory decorator', () => {
119119
});
120120
});
121121

122-
describe('@OnlyContainerCanInstantiate decorator', () => {
122+
describe('@OnlyInstantiableByContainer decorator', () => {
123123

124124
beforeEach(() => {
125125
mockBind.mockClear();
@@ -135,7 +135,7 @@ describe('@OnlyContainerCanInstantiate decorator', () => {
135135
mockBind.mockReturnValue(bind);
136136
class WiredInject { }
137137

138-
expect(OnlyContainerCanInstantiate(WiredInject)).toEqual(constructor);
138+
expect(OnlyInstantiableByContainer(WiredInject)).toEqual(constructor);
139139
expect(mockBind).toBeCalledWith(WiredInject);
140140
expect(mockInstrumentConstructor).toBeCalled;
141141
});

0 commit comments

Comments
 (0)