Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if we provide a service via the bootstrap application providers is that the same as declaring the service as providedIn: root?

Suppose we have a service SomeService that is declared within a library without the providedIn: root injectable metadata configuration.

@Injectable()
export class SomeService { ...}

And within our application we put SomeService in the providers array for bootstrapApplication.

import { SomeService} from 'SomeLibrary';

bootstrapApplication(AppComponent, {
  providers: [
    SomeService,
  ],
});

Will this essentially create a SomeService singleton for the entire application the way providedIn: root does?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As I understand angular dependency injection, this will define the service in the platform injector which is the parent injector of the root injector.

The result is not exactly the same from the dependency injectors point of view.

In reference to your question ("Will this essentially create a SomeService singleton for the entire application") the answer is: "yes"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading