Изменения документа InversifyJS
Редактировал(а) Alexandr Fokin 2021/07/25 01:02
отредактировано Alexandr Fokin
на 2021/07/25 00:58
на 2021/07/25 00:58
отредактировано Alexandr Fokin
на 2021/07/25 00:59
на 2021/07/25 00:59
Изменить комментарий:
Добавлен комментарий
Комментарий
-
Свойства страницы (1 изменено, 0 добавлено, 0 удалено)
-
Объекты (0 изменено, 1 добавлено, 0 удалено)
Подробности
- Свойства страницы
-
- Содержимое
-
... ... @@ -1,0 +1,4 @@ 1 + 2 +InversifyJS: A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript. 3 +(required TypeScript) 4 +https://inversify.io
- XWiki.XWikiComments[0]
-
- Автор
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.cccc1808 - Комментарий
-
... ... @@ -1,0 +1,43 @@ 1 +{{code language="JavaScript"}} 2 +import { Container } from "inversify"; 3 + 4 +import { Type } from "./Type" 5 + 6 +import { IDal, IDalType } from "../model/dal/IDal" 7 +import { DAL } from "../model/dal/DAL" 8 + 9 +import { CounterCreateParams, CounterProps } from "../components/Counter" 10 + 11 +export class ServiceLocator { 12 + 13 + private static Container: Container; 14 + 15 + 16 + public static Init(container: Container | null = null) { 17 + if (container === null) { 18 + container = new Container(); 19 + } 20 + 21 + this.Registry(container); 22 + 23 + this.Container = container; 24 + } 25 + 26 + public static Get<T>(type: Type): T { 27 + var instance = this.Container.get<T>(type.Name); 28 + 29 + if (instance === null) { 30 + throw "Error Get " + type.Name; 31 + } 32 + return instance; 33 + } 34 + 35 + private static Registry(container: Container) { 36 + 37 + container.bind<IDal>(IDalType.Type.Name).to(DAL); 38 + 39 + container.bind<CounterCreateParams>(CounterCreateParams.Type.Name).to(CounterCreateParams); 40 + 41 + } 42 +} 43 +{{/code}} - Дата
-
... ... @@ -1,0 +1,1 @@ 1 +2021-07-25 00:59:38.33