zazoomauro / node-dependency-injection

The NodeDependencyInjection component allows you to standarize and centralize the way objects are constructed in your application.
https://github.com/zazoomauro/node-dependency-injection/wiki
MIT License
280 stars 34 forks source link

JsFileLoader not working with module.exports #145

Closed harpcio closed 4 years ago

harpcio commented 4 years ago

Example:

// repositories/UserRepository.js
class UserRepository 
    get model() {
        return User;
    }

    getAll() {
        return this.findAll();
    }
}

module.exports = UserRepository;

This is working fine:

const di = new ContainerBuilder();
di.register('UserRepository', UserRepository);

But this is not working at all:

// di/repositories.js
module.exports = {
    services: {
        "repositories.user": {
            class: "../repositories/UserRepository"
        },
    }
};
const container = new ContainerBuilder();
const loader = new JsFileLoader(container);
loader.load('./repositories.js');

Then trying to get this object:

container.get('repositories.user');

I received this:

node_modules/node-dependency-injection/dist/lib/InstanceManager.js:122
      throw new _ServiceNotFoundException["default"](id);

The problem is in FileLoader.js, line: 283, I will do PR

rafal-ksiazek-rmtcfm-com commented 4 years ago

https://github.com/zazoomauro/node-dependency-injection/pull/146

rafal-ksiazek-rmtcfm-com commented 4 years ago

Here you have my repository with full code: https://bitbucket.org/remotecraftsmen/erp-system/src/master/server/src/di/services.js

Right now is not working because this tiny bug.

zazoomauro commented 4 years ago

@rafal-ksiazek-rmtcfm-com thanks!

rafal-ksiazek-rmtcfm-com commented 4 years ago

@zazoomauro It's still not working - the change is not updated in npm registry. Maybe you need to update the version of package to 2.6.4?

zazoomauro commented 4 years ago

@rafal-ksiazek-rmtcfm-com build is failing! https://travis-ci.org/github/zazoomauro/node-dependency-injection/jobs/695776915

zazoomauro commented 4 years ago

Looks like npm run test:standardis failing

harpcio commented 4 years ago

Sorry for that: https://github.com/zazoomauro/node-dependency-injection/pull/147

harpcio commented 4 years ago

@zazoomauro Can you merge it?

zazoomauro commented 4 years ago

Merged