-
Notifications
You must be signed in to change notification settings - Fork 21
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
fluentProvide - example #143
Comments
same issue here |
Was about to open same issue. +1million |
The |
Sorry, but still it seems not working. Custom container: export function Provide(symbol: inversifyInterfaces.ServiceIdentifier): any { export function ProvideAsSingleton(identifier: inversifyInterfaces.ServiceIdentifier): any { export function Inject(symbol: inversifyInterfaces.ServiceIdentifier): any { export { container }; Then I provide a class: and then I try to get it: So...what I'm doing wrong? |
I think
|
thanks for your reply, but I still have issue about this. For example, if I want to register controllers or middleware in express in this way:
I get this kind of error:
|
The files need to be required at some point before that. If the file with your class in it isn't evaluated, |
This works for "inversify": "^5.1.1"
|
I got same issue that container is empty even after loading provider module from
export let TYPE = {
Weapon : "Weapon",
Ninja: "Ninja"
}
export interface Weapon {
hit(): string;
}
import {fluentProvide} from "inversify-binding-decorators";
import {TYPE} from "./type";
import {Weapon} from "./weapon";
import "reflect-metadata"
@fluentProvide(TYPE.Weapon).whenTargetTagged("throwable", true).done()
export class Katana implements Weapon {
public hit() {
return "cut!";
}
}
import { Container} from "inversify";
import "reflect-metadata";
import {buildProviderModule} from "inversify-binding-decorators";
import {TYPE} from "./type";
const container = new Container();
container.load(buildProviderModule());
container.isBoundTagged(TYPE.Weapon, "throwable", true);
export {
container
}
import {Weapon} from "./sample/weapon";
import {container} from "./sample/ioc";
import {TYPE} from "./sample/type";
describe("Typescript usage suite", () => {
it("should be able to execute a test", () => {
const katana: Weapon = container.getTagged<Weapon>(TYPE.Weapon, "throwable", true);
katana.hit();
});
});
|
Did you find a workaround for this ? Thanks. Edit : I put this here, I don't know if it will help someone but the problem I had was just a problem of module imports. I start working again with node.js and javascript in general and I completely forgot about import order. So when you call buildProviderModule() be sure to import all the injectable entities beforehand. In my case I created a loader import file which is in charge for loading everything before the call. You can find an exemple here : https://github.com/inversify/inversify-express-example/tree/master/BindingDecorators. Be careful to respect the import "path_to_file" syntax so that Typescript understands you want to force import the module without using it right now. |
Could you please provide a full fluentProvide example?
I have this kind of issue:
The issue is at:
the error is:
How can I use fluent provider?
thanks
The text was updated successfully, but these errors were encountered: