joist-framework / joist

A small (~2kb) library to help with the creation of web components and web component based applications
121 stars 6 forks source link

@joist/di: add multi providers. #1083

Open deebloo opened 1 month ago

deebloo commented 1 month ago

And multi providers. This comes from frameworks like angular where you can provide multiple instances of a particular provider. They get returned as an array. There are some use cases where this can be very useful but it would make a number of things more complex and could potentially hurt performance.

@injectable({
  multi: true
})
class ServiceA { }

const app = new Injector({
  providers: [
    { provide: ServiceA, use: ServiceA },
    { provide: ServiceA, use: ServiceA }
  ]
})

app.inject(ServiceA); // [ServiceA, ServiceA]