UNPKG

2.74 kBJavaScriptView Raw
1/**
2 * @license
3 * MOST Web Framework 2.0 Codename Blueshift
4 * Copyright (c) 2017, THEMOST LP All rights reserved
5 *
6 * Use of this source code is governed by an BSD-3-Clause license that can be
7 * found in the LICENSE file at https://themost.io/license
8 */
9///
10var AbstractMethodError = require("./errors").AbstractMethodError;
11var AbstractClassError = require("./errors").AbstractClassError;
12var LangUtils = require("./utils").LangUtils;
13var Symbol = require('symbol');
14
15/**
16 *
17 * @class
18 * @abstract
19 * @param {string=} configPath
20 */
21// eslint-disable-next-line no-unused-vars
22function IApplication(configPath) {
23 if (this.constructor === IApplication.prototype.constructor) {
24 throw new AbstractClassError();
25 }
26}
27
28/**
29 * Registers an application strategy e.g. an singleton service which to be used in application contextr
30 * @param {Function} serviceCtor
31 * @param {Function} strategyCtor
32 * @returns IApplication
33 */
34// eslint-disable-next-line no-unused-vars
35IApplication.prototype.useStrategy = function(serviceCtor, strategyCtor) {
36 throw new AbstractMethodError();
37};
38
39/**
40* @param {Function} serviceCtor
41* @returns {boolean}
42*/
43// eslint-disable-next-line no-unused-vars
44IApplication.prototype.hasStrategy = function(serviceCtor) {
45 throw new AbstractMethodError();
46};
47
48/**
49 * Gets an application strategy based on the given base service type
50 * @param {Function} serviceCtor
51 * @return {*}
52 */
53// eslint-disable-next-line no-unused-vars
54IApplication.prototype.getStrategy = function(serviceCtor) {
55 throw new AbstractMethodError();
56};
57/**
58 * @returns {ConfigurationBase}
59 */
60IApplication.prototype.getConfiguration = function() {
61 throw new AbstractMethodError();
62};
63
64
65/**
66 *
67 * @class
68 * @abstract
69 * @param {IApplication} app
70 */
71// eslint-disable-next-line no-unused-vars
72function IApplicationService(app) {
73 if (this.constructor === IApplicationService.prototype.constructor) {
74 throw new AbstractClassError();
75 }
76}
77
78/**
79 * @returns {IApplication}
80 */
81IApplicationService.prototype.getApplication = function() {
82 throw new AbstractMethodError();
83};
84var applicationProperty = Symbol('application');
85/**
86 *
87 * @class
88 * @constructor
89 * @param {IApplication} app
90 */
91// eslint-disable-next-line no-unused-vars
92function ApplicationService(app) {
93 ApplicationService.super_.bind(this)(app);
94 this[applicationProperty] = app;
95}
96LangUtils.inherits(ApplicationService,IApplicationService);
97/**
98 * @returns {IApplication}
99 */
100ApplicationService.prototype.getApplication = function() {
101 return this[applicationProperty];
102};
103
104module.exports.IApplication = IApplication;
105module.exports.IApplicationService = IApplicationService;
106module.exports.ApplicationService = ApplicationService;