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

Async factories #30

Open
schiller-manuel opened this issue Sep 3, 2020 · 1 comment
Open

Async factories #30

schiller-manuel opened this issue Sep 3, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@schiller-manuel
Copy link

schiller-manuel commented Sep 3, 2020

Did you consider adding support for async factories?

This is how an async factory might be used:

class Server {
    public async init() {
    }
}

async function serverFactory() {
    const server = new Server();
    await server.init();
    return server;
}

class App {
    public static inject = ['server'];
    constructor(private server: Server) {
        // server is already initialized
   }
}

const injector = createInjector().provideFactory('server', serverFactory);
const app = await injector.injectClass(App);
@nicojs
Copy link
Owner

nicojs commented Sep 3, 2020

Yeah, this would be a great addition. Have thought about it, sure can be added, just haven't got around to it yet.

I find your solution elegant. I was thinking about adding provideAsyncFactory, but if we could add it with the existing provideFactory that would be better.

@nicojs nicojs added the enhancement New feature or request label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants