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

Question: Circular Dependencies #46

Open
snnsnn opened this issue Jan 19, 2022 · 2 comments
Open

Question: Circular Dependencies #46

snnsnn opened this issue Jan 19, 2022 · 2 comments

Comments

@snnsnn
Copy link
Contributor

snnsnn commented Jan 19, 2022

Please can you address how to handle circular dependencies, with an example if possible.

@nicojs
Copy link
Owner

nicojs commented Jan 21, 2022

You mean something like this?

import { createInjector } from "typed-inject";

class HttpClient {
  public static inject = ["logger"] as const;
  public service?: MyService;
}

class MyService {
  constructor(private http: HttpClient) {
    http.service = this; // Assign circular dependency
  }
  public static inject = ["httpClient"] as const;
}

const appInjector = createInjector().provideClass("httpClient", HttpClient);

const myService = appInjector.injectClass(MyService);

If not, please try to explain with a code example.

@snnsnn
Copy link
Contributor Author

snnsnn commented Jan 21, 2022

@nicojs I was asking for something more like a direct dependency between two services, or dependency through a third service.

A -> B -> A
A -> B -> C -> A

I don't have a concrete example at the moment, just trying to assess potentials of different IOC libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants