inversify-binding-decorators 4.0 does not any more have makeProvideDecorator and makeFluentProvideDecorator exports used in the example.
Any chance you could update the README with how it's supposed to be used now?
Do you know already how to refresh examples written in here https://github.com/lukeautry/tsoa#dependency-injection-or-ioc ? I would really love to make my controllers more independent of imports.
I tried really hard :D but I failed.
Here is my ioc.ts
import { Container, inject, interfaces } from 'inversify';
import {
autoProvide,
provide,
fluentProvide,
} from 'inversify-binding-decorators';
let provideNamed = function (
identifier: string | symbol | interfaces.Newable<any> | interfaces.Abstract<any>,
name: string,
) {
return fluentProvide(identifier)
.whenTargetNamed(name)
.done();
};
let provideSingleton = function (
identifier: string | symbol | interfaces.Newable<any> | interfaces.Abstract<any>,
) {
return fluentProvide(identifier)
.inSingletonScope()
.done();
};
export { autoProvide, provide, provideSingleton, provideNamed, inject };
Pay attention that I removed makeProvideDecorator, makeFluentProvideDecorator because "inversify-binding-decorators" package does not export them more.
I had to remove also these lines
let iocContainer = new Container();
let provide = makeProvideDecorator(iocContainer);
let fluentProvider = makeFluentProvideDecorator(iocContainer);
Because I have another place to make Container instance, there I have it in container.ts
const utils = ...
const useCases = ...
const services = ...
const servicesClients = ...
const repositories = ...
const useCases = new ContainerModule((bind: Bind) => {
bind<GetClientUseCase>(USE_CASE_IDENTIFIER.GetClientUseCase).to(GetClientUseCase);
bind<AddClientUseCase>(USE_CASE_IDENTIFIER.AddClientUseCase).to(AddClientUseCase);
bind<UpdateClientUseCase>(USE_CASE_IDENTIFIER.UpdateClientUseCase).to(UpdateClientUseCase);
bind<DeleteClientUseCase>(USE_CASE_IDENTIFIER.DeleteClientUseCase).to(DeleteClientUseCase);
bind<GetClientsUseCase>(USE_CASE_IDENTIFIER.GetClientsUseCase).to(GetClientsUseCase);
});
export const loadAll = (): Container => {
const container = new Container();
container.load(buildProviderModule());
container.load(utils, useCases, services, servicesClients, repositories);
return container;
};
Then I tried to use this configuration to inject useCases into my controllers but it didn't help. tsoa generate worked flawlessly but I got runtime errors - TSOA couldn't find my controllers. So I decided to add to container.ts
const controllers = new ContainerModule((bind: Bind) => {
bind<GetClientController>(GetClientController).to(GetClientController);
});
and load it into container
export const loadAll = (): Container => {
const container = new Container();
container.load(buildProviderModule());
container.load(utils, useCases, services, servicesClients, repositories, controllers);
return container;
};
And what the result was - it made runtime finding the controller but throwing more exceptional stuff at me :(
As I am like a child in a mist, I don't really grasp very specific details of IoC and Inversify. But I leave it here, maybe someone would pick it up from here.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
use an older version --> "inversify-binding-decorators": "^3.2.0"
As at the time of wriiting this, I'm using inversify-binding-decorators version ^4.0.0 (which was the latest)
Update the file like so...
_./inversify/ioc.ts_
import {
autoProvide,
fluentProvide,
provide
} from "inversify-binding-decorators";
import { Container, interfaces, inject } from "inversify";
const iocContainer = new Container();
const provideNamed = (
identifier:
| string
| symbol
| interfaces.Newable<any>
| interfaces.Abstract<any>,
name: string
) =>
fluentProvide(identifier)
.whenTargetNamed(name)
.done();
const provideSingleton = (
identifier:
| string
| symbol
| interfaces.Newable<any>
| interfaces.Abstract<any>
) =>
fluentProvide(identifier)
.inSingletonScope()
.done();
export {
iocContainer,
autoProvide,
provide,
provideSingleton,
provideNamed,
inject
};