Переключить навигацию
Поиск
Вход
Home
Перечень страниц
Каталог пользователей
Список приложений
Глобальные
Перечень Вики
Разработка
…
Библиотеки
Dependency Injection
InversifyJS
Комментарий к
InversifyJS
Редактировал(а)
Alexandr Fokin
2021/07/25 01:02
Alexandr Fokin
,
2021/07/25 04:59
import
{ Container } from
"inversify"
;
import
{ Type } from
"./Type"
import
{ IDal, IDalType } from
"../model/dal/IDal"
import
{ DAL } from
"../model/dal/DAL"
export
class
ServiceLocator {
private
static
Container
:
Container;
public
static
Init(container
:
Container
|
null
=
null
) {
if
(container
===
null
) {
container
=
new
Container();
}
this
.Registry(container);
this
.Container
=
container;
}
public
static
Get
<
T
>
(type
:
Type)
:
T {
var
instance
=
this
.Container.get
<
T
>
(type.Name);
if
(instance
===
null
) {
throw
"Error Get "
+
type.Name;
}
return
instance;
}
private
static
Registry(container
:
Container) {
container.bind
<
IDal
>
(IDalType.Type.Name).to(DAL);
}
}
×
Постоянная ссылка
×
Удалить
Вы уверены, что хотите удалить этот комментарий?
import { Type } from "./Type"
import { IDal, IDalType } from "../model/dal/IDal"
import { DAL } from "../model/dal/DAL"
export class ServiceLocator {
private static Container: Container;
public static Init(container: Container | null = null) {
if (container === null) {
container = new Container();
}
this.Registry(container);
this.Container = container;
}
public static Get<T>(type: Type): T {
var instance = this.Container.get<T>(type.Name);
if (instance === null) {
throw "Error Get " + type.Name;
}
return instance;
}
private static Registry(container: Container) {
container.bind<IDal>(IDalType.Type.Name).to(DAL);
}
}