0
|
1 define([ "dojo/_base/declare", "../safe" ], function(declare, safe) {
|
|
2 return declare(
|
|
3 null,
|
|
4 {
|
|
5 _params : null,
|
|
6
|
|
7 _repositories : null,
|
|
8
|
|
9 constructor : function(opts) {
|
|
10 this._params = opts || {};
|
|
11 this._repositories = {};
|
|
12 },
|
|
13
|
|
14 getRepository : function(name) {
|
|
15 safe.argumentNotEmptyString(name, "name");
|
|
16 var repo = this._repositories[name];
|
|
17 if (!repo) {
|
|
18 repo = this._params[name];
|
|
19 if (!repo)
|
|
20 throw new Error("The repository '" + name +
|
|
21 "' isn't found");
|
|
22 if (repo instanceof Function)
|
|
23 repo = new repo(); // factory method or constructor
|
|
24 if (repo.initialize) {
|
|
25 repo.initialize({
|
|
26 dataContext : this
|
|
27 });
|
|
28 } else if (repo.setDataContext) {
|
|
29 repo.setDataContext(this);
|
|
30 }
|
|
31 this._repositories[name] = repo;
|
|
32 }
|
|
33
|
|
34 return repo;
|
|
35 },
|
|
36
|
|
37 dispose : function() {
|
|
38 for( var name in this._repositories) {
|
|
39 var r = this._repositories[name];
|
|
40 if (r.dispose)
|
|
41 r.dispose();
|
|
42 }
|
|
43 }
|
|
44 });
|
|
45 }); |