openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Tree-Shaking: use providedIn 'root' instead of provider array

Open chillbirdo opened this issue 3 years ago • 0 comments

Dear community, Dear Ferdi,

thanks for that awesome generator!

For a couple of reasons, mainly tree-shakability (see: https://stackoverflow.com/a/53008692/13468177 ), it is more efficient to use

@Injectable({
  providedIn: 'root',
})

instead of providing the Services in the Module's providers array. This could also be optional with a flag.

In our case we include a module in distinct bundles, some of them do not even make use of the services or only a few of them. With the current solution all of the services are included in all of our bundles, needlessly.

Many Thanks, Gilbert

chillbirdo avatar Jun 14 '22 15:06 chillbirdo