'How can I use APP_INITIALIZER in a nx library?

I've got an nx app shell that uses a primary view library, and this library depends on services that require initialization prior to first use. If I were in native Angular, I'd use APP_INITIALIZER and then my provider would pause during bootstrap, but my libs don't have a bootstrap.

I can't just move the service to the top-level app and have this work, can I? The service won't be seen by the lower-level modules properly. What's the best approach here?

EDIT: Since somebody asked, my final result...

I couldn't use APP_INITIALIZER in the library, but I only needed a thin wrapper in the app before deferring to code from the library.

From @NGModule...

providers: [{ 
    provide: APP_INITIALIZER, 
    useFactory: authentication_preload, 
    deps: [AuthenticationService], 
    multi: true 
},...]

And then that referenced factory...

export function authentication_preload(authService: AuthenticationService) {
  return () => authService.initialize();
}

AuthenticationService was imported without any fanfare from one of the libraries I loaded, and initialize returned a promise that handled everything I wanted done and resolved once it was ready. End result: Application boot couldn't continue until the auth service was ready to work with the interceptors.



Solution 1:[1]

mongo shell JS version:

 db.collection.update({},
 {
  $set: {
    "meeting.$[m].dates.$[k].student_id": "value"
  }
 },
{
   arrayFilters: [
     {
       "m.id": "1641278777739"
    },
    {
       "k.id": 1641377970597
    }
  ]
})

explained: You use two arrayFilters to select the exact nesteed object where you will update in your case the student_id key with the new value ... javascript playground

php version:

  $db->collection->update([],
 [
   '$set'=>["meeting.$[m].dates.$[k].student_id" => "value" ]
 ],
 [
   'arrayFilters'=>  [
                       "m.id"=> "1641278777739" , 
                       "k.id"=>1641377970597
                     ]
 ]
);
  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1