Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFactory not work without dependencies field #8

Closed
CheerlessCloud opened this issue Aug 9, 2019 · 1 comment
Closed

useFactory not work without dependencies field #8

CheerlessCloud opened this issue Aug 9, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@CheerlessCloud
Copy link

When provider definition contain useFactory without dependencies container compile will fail:

/workdir/node_modules/@ukitgroup/ioc/dist/instance-wrappers/factory-instance-wrapper.js:23
        const resolvedDependencies = this.dependencies.map(dependencyResolver);
                                                       ^

TypeError: Cannot read property 'map' of undefined
    at FactoryInstanceWrapper.createInstance (/workdir/node_modules/@ukitgroup/ioc/dist/instance-wrappers/factory-instance-wrapper.js:23:56)
    at Injector.resolveProvider (/workdir/node_modules/@ukitgroup/ioc/dist/injector.js:46:18)
    at moduleForResolve.getProviders.forEach.provider (/workdir/node_modules/@ukitgroup/ioc/dist/injector.js:19:18)
    at Array.forEach (<anonymous>)
    at Injector.resolveModule (/workdir/node_modules/@ukitgroup/ioc/dist/injector.js:18:41)
    at modules.forEach.currentModule (/workdir/node_modules/@ukitgroup/ioc/dist/injector.js:14:18)
    at Map.forEach (<anonymous>)
    at Injector.resolveGraph (/workdir/node_modules/@ukitgroup/ioc/dist/injector.js:13:22)
    at Container.compile (/workdir/node_modules/@ukitgroup/ioc/dist/container.js:45:18)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/gleb/110/model/domain/connect.js:5:25)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

Provider definition:

{
  token: 'AwesomeProviderForLegacyCode',
  useFactory: () => {
    const feature = require('../legacy/feature');
    if (feature.enabled) {
      return feature;
    }
    return require('../legacy/feature/fallback');
  },
}

I think this case should be cover by validation and by default [] for dependencies.

@Goodluckhf Goodluckhf added the bug Something isn't working label Aug 9, 2019
@Goodluckhf
Copy link
Owner

#10 Will be fixed

Goodluckhf added a commit that referenced this issue Aug 11, 2019
#8: useFactory not work without dependencies field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants