2

Sry for my english. I have next problem. I have three entities: DomainManager, Domain and Node. DomainManager is singleton that able to create list of Domain objects. Each Domain can create list of Node objects:

DomainManager 1<>-----* Domain 1<>----* Node

I want:

  1. Node implementation can inject corresponding parent Domain to himself.
  2. Node implementation can inject Domain manager instance too.

class NodeImpl { @Inject NodeImpl(Domain parentDomain, DomainManager domainManager) {

} }

How can i do this?

1 Answers1

0

It's difficult to answer without knowing exactly what you want to do with your Nodes and Domains but, following jfpoilpret's (+1) advice using @Assisted injected parameters might help you. See this answer or (even better) this for details of how this works.

Having said that, your constructor for NodeImpl might look like this:

@Inject
public NodeImpl(DomainManager manager, @Assisted Domain) {}

You then create a NodeFactory to hand back instances of NodeImpl. However, you still need something that uses the NodeFactory to figure out which Nodes are associated with which Domains.

Community
  • 1
  • 1
alpian
  • 4,668
  • 1
  • 18
  • 19