At first, sorry for my poor english, i hope its understandable.

We have the following classes and we want to inject an
ICommunicationManager-instance to the  XyzDevice ! The Problem is a
dependency in the creation order...

public class DeviceLog {
        private final IDevice device;

        public DeviceLog(IDevice device) {
                this.device = device;
        }

        //Methods to write log messages to a specific file for the given
device...
}

public class XyzDevice implements IDevice {

        private final DeviceLog deviceLog;

        private final ICommunicationManager communicationManager;

        public XyzDevice() {
                this.deviceLog = new DeviceLog(this);

                this.communicationManager= new 
XzyCommunicationManager(deviceLog);
        }
}

_________________________________________________

We want to inject an ICommunicationManager implementation to the
XyzDevice-constructor, that is easy (using a Module). But how to
create the XzyCommunicationManager, it needs a DeviceLog which needs
the device instance ? We dont want to remove the final-modifiers of
our fields.

A solution without Guice could look like this:

public XyzDevice(ICommunicationManagerFactory factory) {
                this.deviceLog = new DeviceLog(this);

                this.communicationManager=
factory.createCommunicationManager(deviceLog);
}

Can i do this with Guice without the need of an factory ?

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to