Skip to content

Support injecting providers into dataSourceFactory #1294

@brandon-leapyear

Description

@brandon-leapyear

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I would like to provide my own DataSource, but I need to inject my ConfigService so that I can do things in my DataSource depending on configuration.

Describe the solution you'd like

The most straightforward solution is to provide a dataSourceFactoryInject option.

A bigger change (which I think makes more sense) would be to remove dataSourceFactory and add

dataSourceProviderModify: (provider) => provider
entityManagerProviderModify: (provider) => provider

which passes in the default provider, and the user can modify whatever they want, e.g.

dataSourceProviderModify: (provider) => ({
  ...provider,
  useFactory: (typeOrmOptions, configService) => {
    return new MyDataSource(typeOrmOptions, configService)
  },
  inject: [...provider.inject, ConfigService],
})

Teachability, documentation, adoption, migration strategy

See solution.

What is the motivation / use case for changing the behavior?

See problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions