You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

container-ioc

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

container-ioc - npm Package Compare versions

Comparing version

to
1.6.4

2

package.json
{
"name": "container-ioc",
"version": "1.6.3",
"version": "1.6.4",
"description": "Dependency Injection and IoC container",

@@ -5,0 +5,0 @@ "author": "Alexander Kozlov",

@@ -40,3 +40,3 @@ ![alt text](http://abcselfstorageperth.com.au/wp-content/uploads/2014/08/icon-container-storage1.png)

class Service implements IService {
constructor(@Inject('ISerivce') public service: IService) {}
constructor(@Inject('IService') public service: IService) {}
}

@@ -52,3 +52,29 @@

```
### Best Practise: use InjectionToken instances for tokens instead of string/class literals:
##### Without InjectionToken:
```typescript
interface IService {}
@Injectable()
class ConcreteService {}
container.register({ token: 'IService', useClass: ConcreteService });
container.resolve('IService');
```
##### With InjectionToken
```Typescript
interface IService {}
const TService = new InjectionToken<IService>('IService'); // T stands for Token, you can pick another prefix
@Injectable()
class ConcreteService {}
container.register({ token: TService, useClass: ConcreteService });
container.resolve(TService);
```
### Examples:

@@ -80,31 +106,2 @@ * [using factory](https://github.com/thohoh/container-ioc/blob/master/examples/use-factory.ts)

### Injection Token
> InjectionToken helps to avoid hardcoded strings in your code.
##### Without InjectionToken:
```typescript
interface IService {}
@Injectable()
class ConcreteService {}
container.register({ token: 'IService', useClass: ConcreteService });
container.resolve('IService');
```
##### With InjectionToken
```Typescript
interface IService {}
const TService = new InjectionToken<IService>('IService'); // T stands for Token, you can pick another prefix
@Injectable()
class ConcreteService {}
container.register({ token: TService, useClass: ConcreteService });
container.resolve(TService);
```
### Hierarchical containers.

@@ -111,0 +108,0 @@ > if a provider wasn't found in a container it will look up in ascendant containers if there are any: