@@ -29,31 +29,8 @@ export class RepositoryBooter extends BaseArtifactBooter {
29
29
public repositoryOptions : ArtifactOptions = { } ,
30
30
) {
31
31
super ( ) ;
32
-
33
- /**
34
- * Repository Booter requires the use of RepositoryMixin (so we have `app.repository`)
35
- * for binding a Repository Class. We check for it's presence and run
36
- * accordingly.
37
- */
38
- // tslint:disable-next-line:no-any
39
- if ( ! this . app . repository ) {
40
- console . warn (
41
- 'app.repository() function is needed for RepositoryBooter. You can add ' +
42
- 'it to your Application using RepositoryMixin from @loopback/repository.' ,
43
- ) ;
44
-
45
- /**
46
- * If RepositoryMixin is not used and a `.repository()` function is not
47
- * available, we change the methods to be empty so bootstrapper can
48
- * still run without any side-effects of loading this Booter.
49
- */
50
- this . configure = async ( ) => { } ;
51
- this . discover = async ( ) => { } ;
52
- this . load = async ( ) => { } ;
53
- } else {
54
- // Set Repository Booter Options if passed in via bootConfig
55
- this . options = Object . assign ( { } , RepositoryDefaults , repositoryOptions ) ;
56
- }
32
+ // Set Repository Booter Options if passed in via bootConfig
33
+ this . options = Object . assign ( { } , RepositoryDefaults , repositoryOptions ) ;
57
34
}
58
35
59
36
/**
@@ -62,10 +39,24 @@ export class RepositoryBooter extends BaseArtifactBooter {
62
39
*/
63
40
async load ( ) {
64
41
await super . load ( ) ;
65
- this . classes . forEach ( cls => {
66
- // tslint:disable-next-line:no-any
67
- this . app . repository ( cls ) ;
68
- } ) ;
42
+ /**
43
+ * If Repository Classes were discovered, we need to make sure RepositoryMixin
44
+ * was used (so we have `app.repository()`) to perform the binding of a
45
+ * Repository Class.
46
+ */
47
+ if ( this . classes . length > 0 ) {
48
+ if ( ! this . app . repository ) {
49
+ console . warn (
50
+ 'app.repository() function is needed for RepositoryBooter. You can add ' +
51
+ 'it to your Application using RepositoryMixin from @loopback/repository.' ,
52
+ ) ;
53
+ } else {
54
+ this . classes . forEach ( cls => {
55
+ // tslint:disable-next-line:no-any
56
+ this . app . repository ( cls ) ;
57
+ } ) ;
58
+ }
59
+ }
69
60
}
70
61
}
71
62
0 commit comments