question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wire/inject/resolve strictly binds service to specific container

See original GitHub issue

Hi, i use @owja/ioc in Node.js app.

In my app i have a service (for example named MyService) that has one dependency.

I use wire function for define dependency.

In my case i have two containers in two apps and i want to use MyService in both of containers

But the wire function is created for a specific container strictly binds each service to the container.

In my case i act like this:

const createMyService = wire => class MyService {
  constructor () {
    wire(this, 'myDependency', TYPE.myDependency)
  }
};

But it looks more like a trick.

How can i properly create service for use it in any container?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
krutoocommented, Mar 18, 2022

@hbroer thank you

1reaction
hbroercommented, Aug 24, 2021
// app 1 bootstrap

import { MyService, MyServiceSymbol } from "@some/lib";
import { Foo } from "./services/foo";

const container = new Container();

const TYPE = {
  "myService": MyServiceSymbol;
}

container.bind(TYPE.myService).toFactory(() => new MyService(Foo));

export {container, TYPE};
// app 2 bootstrap

import { MyService, MyServiceSymbol } from "@some/lib";
import { Bar } from "./services/Bar";

const container = new Container();

const TYPE = {
  "myService": MyServiceSymbol;
}

container.bind(TYPE.myService).toFactory(() => new MyService(Bar));

export {container, TYPE};
// MyService  Lib

export class MyService {
  constructor(public myDependency) {}

  doSomething () {
    this.myDependency.something(); 
  }
}

I think that is the optimal way. Especially with plain javascript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service | Kubernetes
An ExternalName Service is a special case of Service that does not have selectors and uses DNS names instead. For more information, see...
Read more >
Strictly Come Dancing 2022: Hamza Yassin wins glitterball ...
Hamza Yassin, Fleur East, Helen Skelton and Molly Rainford all fought to land the glitterball trophy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found