-
Notifications
You must be signed in to change notification settings - Fork 64
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
Multi-injection support #28
Comments
Hi @julianosam , It is not possible with the current version, but I like the idea. We can think something to next release |
I had the same requirement and found a workaround: // components/base.ts
export abstract class BaseClass {
} // components/impl1.ts
import { Provides } from "typescript-ioc";
import { BaseClass } from "./base";
@Provides(BaseClass)
export class ImplClass1 extends BaseClass {
} // components/impl2.ts
import { Provides } from "typescript-ioc";
import { BaseClass } from "./base";
@Provides(BaseClass)
export class ImplClass2 extends BaseClass {
} // components/index.ts
import { Container } from "typescript-ioc";
import { BaseClass } from "./base";
import { ImplClass1 } from "./impl1";
import { ImplClass2 } from "./impl2";
// this is where the magic happens
export class ImplCollection extends Array<BaseClass> {
constructor() {
super();
this.push(Container.get(ImplClass1) as BaseClass);
this.push(Container.get(ImplClass2) as BaseClass);
}
} // main.ts
import { AutoWired, Inject } from "typescript-ioc";
import { ImplCollection } from "./components/index";
@AutoWired
class Consumer {
@Inject
private implementations: ImplCollection;
}
let consumer = new Consumer(); |
Any updates on this? @Name('A')
@Provies(BaseClass)
export class A extend BaseClass { ... }
Then you can do something like
export class B {
@inject('A')
public _myBaseBlassWhichIsA: BaseClass;
} Below is an example (described in a test) of the unity container behavior with names and multiple implementations: |
any intentions to implement this? |
Aw, just ran into this. |
Hey guys! I am heavily using this library in one of my projects, and just ran into a good use case for multi-injection. More specifically, I want to to something like (pseudo code):
Let me know your thoughts!
The text was updated successfully, but these errors were encountered: