I'm new to Guice and wanted to get some advice on how to use it with
our application that uses the command pattern. The app has a
CommandMap which maps Events to Commands.
commandMap.map(FooEvent.EVENT_TYPE, FooCommand.class);
Events are dispatched from an EventDispatcher and the CommandMap then
routes the Event to the Command.
// dispatched from somewhere
eventDispatcher.dispatchEvent(new FooEvent(FooEvent.EVENT, payload));
// CommanMap.java
protected void routeEventToCommand(IEvent e, Class commandClass) {
ICommand command = (ICommand) _injector.getInstance(commandClass);
command.execute(e);
}
The command executes but the event must be cast to get it's payload.
// FooCommand.java
void execute(IEvent e) {
FooEvent = (FooEvent) e;
e.getSomeObject();
}
I'd like to avoid casting. It is possible to inject the event into the
command? I've tried various configurations with Guice but always end
up with a new instance of the event in the command rather than the one
that was dispatched.
thanks!
--
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.