Изменения документа 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 01:02
на 2021/07/25 01:02
Изменить комментарий:
Добавлен тег [TypeScript]
Комментарий
-
Свойства страницы (3 изменено, 0 добавлено, 0 удалено)
-
Объекты (0 изменено, 1 добавлено, 0 удалено)
Подробности
- Свойства страницы
-
- Родительский документ
-
... ... @@ -1,1 +1,1 @@ 1 -Разработка.Frontend.Библиотеки. JavaScriptDependencyInjection.WebHome1 +Разработка.Frontend.Библиотеки.Dependency Injection.WebHome - Теги
-
... ... @@ -1,0 +1,1 @@ 1 +TypeScript - Содержимое
-
... ... @@ -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,39 @@ 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 +export class ServiceLocator { 10 + 11 + private static Container: Container; 12 + 13 + 14 + public static Init(container: Container | null = null) { 15 + if (container === null) { 16 + container = new Container(); 17 + } 18 + 19 + this.Registry(container); 20 + 21 + this.Container = container; 22 + } 23 + 24 + public static Get<T>(type: Type): T { 25 + var instance = this.Container.get<T>(type.Name); 26 + 27 + if (instance === null) { 28 + throw "Error Get " + type.Name; 29 + } 30 + return instance; 31 + } 32 + 33 + private static Registry(container: Container) { 34 + 35 + container.bind<IDal>(IDalType.Type.Name).to(DAL); 36 + 37 + } 38 +} 39 +{{/code}} - Дата
-
... ... @@ -1,0 +1,1 @@ 1 +2021-07-25 00:59:38.33