mastercontroller 1.1.15 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MasterControl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // MasterControl - by Alexander rich
2
- // version 1.0.18
2
+ // version 1.0.19
3
3
 
4
4
  var url = require('url');
5
5
  var fileserver = require('fs');
@@ -9,6 +9,7 @@ var fs = require('fs');
9
9
  var url = require('url');
10
10
  var path = require('path');
11
11
 
12
+
12
13
  class MasterControl {
13
14
  controllerList = {}
14
15
  viewList = {}
@@ -16,6 +17,15 @@ class MasterControl {
16
17
  _root = null
17
18
  _environmentType = null
18
19
  _serverProtocol = null
20
+ _scopedList = []
21
+
22
+ #loadTransientListClasses(name, params){
23
+ Object.defineProperty(this.requestList, name, {
24
+ get: function() {
25
+ return new params();
26
+ }
27
+ });
28
+ }
19
29
 
20
30
  get env(){
21
31
  return require(`${this.root}/config/environments/env.${this.environmentType}.json`);
@@ -96,13 +106,48 @@ class MasterControl {
96
106
  };
97
107
  }
98
108
 
99
- // adds your class to the --------- todo
100
- register(name, param){
101
- if(name && param){
102
- this.requestList[name] = param;
109
+ /*
110
+ Services are created each time they are requested.
111
+ It gets a new instance of the injected object, on each request of this object.
112
+ For each time you inject this object is injected in the class, it will create a new instance.
113
+ */
114
+ addTransient(name, params){
115
+ if(name && params){
116
+ this.#loadTransientListClasses(name, params);
103
117
  }
118
+
104
119
  }
105
120
 
121
+ /*
122
+ Services are created on each request (once per request). This is most recommended for WEB applications.
123
+ So for example, if during a request you use the same dependency injection,
124
+ in many places, you will use the same instance of that object,
125
+ it will make reference to the same memory allocation
126
+ */
127
+ addScoped(name, params){
128
+ if(name && params){
129
+ this._scopedList[name] = params;
130
+ }
131
+ }
132
+
133
+ /*
134
+ Services are created once for the lifetime of the application. It uses the same instance for the whole application.
135
+ */
136
+ addSingleton(name, params){
137
+ if(name && params){
138
+ this.requestList[name] = new params();
139
+ }
140
+ }
141
+
142
+ // adds your class instance to the request object.
143
+ register(name, params){
144
+ if(name && params){
145
+ this.requestList[name] = params;
146
+ }
147
+ }
148
+
149
+
150
+
106
151
  // adds all the server settings needed
107
152
  serverSettings(settings){
108
153
 
package/MasterRouter.js CHANGED
@@ -1,6 +1,4 @@
1
-
2
-
3
- // version 1.0.17
1
+ // version 1.0.18
4
2
 
5
3
  var master = require('./MasterControl');
6
4
  var tools = require('./MasterTools');
@@ -86,6 +84,14 @@ const path = require('path')
86
84
  }
87
85
  };
88
86
 
87
+ var loadScopedListClasses = function(){
88
+ for (var key in master._scopedList) {
89
+ var className = master._scopedList[key];
90
+ master.requestList[key] = new className();
91
+ };
92
+ };
93
+
94
+
89
95
  class MasterRouter {
90
96
  currentRouteName = null
91
97
  _routes = {}
@@ -236,7 +242,8 @@ class MasterRouter {
236
242
 
237
243
  _call(requestObject){
238
244
 
239
- tools.combineObjects(requestObject, master.requestList);
245
+ tools.combineObjects(master.requestList, requestObject);
246
+ requestObject = master.requestList;
240
247
  var Control = require(`${currentRoute.root}/app/controllers/${tools.firstLetterlowercase(requestObject.toController)}Controller`);
241
248
  if(Control === null){
242
249
  Control = require(`${currentRoute.root}/app/controllers/${tools.firstLetterUppercase(requestObject.toController)}Controller`);
@@ -263,6 +270,8 @@ class MasterRouter {
263
270
  }
264
271
 
265
272
  load(rr){ // load the the router
273
+
274
+ loadScopedListClasses();
266
275
  var $that = this;
267
276
  var requestObject = Object.create(rr);
268
277
  requestObject.pathName = requestObject.pathName.replace(/^\/|\/$/g, '').toLowerCase();
package/package.json CHANGED
@@ -17,5 +17,5 @@
17
17
  "scripts": {
18
18
  "test": "echo \"Error: no test specified\" && exit 1"
19
19
  },
20
- "version": "1.1.15"
20
+ "version": "1.1.16"
21
21
  }