Skip to content

Instantly share code, notes, and snippets.

@ilopmar
Last active December 15, 2015 22:30
Show Gist options
  • Save ilopmar/a55af3346aaa788c632d to your computer and use it in GitHub Desktop.
Save ilopmar/a55af3346aaa788c632d to your computer and use it in GitHub Desktop.
package com.example
import ratpack.guice.Guice
import ratpack.server.RatpackServer
public class MyApp {
public static void main(String[] args) throws Exception {
RatpackServer.start { spec ->
spec.registry {
Guice.registry { r ->
r.bind(MyService.class)
}
}
.handlers { chain ->
chain.get { ctx ->
MyService myService = ctx.get(MyService.class)
myService.myMethod()
ctx.render("Finished!")
}
}
}
}
}
package example;
import ratpack.guice.Guice;
import ratpack.server.RatpackServer;
public class MyApp {
public static void main(String[] args) throws Exception {
RatpackServer.start(spec -> spec
.registry(Guice.registry(r -> r
.bind(MyService.class)
))
.handlers(chain -> chain
.get(ctx -> {
MyService myService = ctx.get(MyService.class);
myService.myMethod();
ctx.render("Finished");
})
));
}
}
package com.example
class MyService {
void myMethod() {
System.out.println("calling myMethod");
}
}
@danhyun
Copy link

danhyun commented Dec 15, 2015

Yes, just change to

public class MyApp {
  public static void main(String[] args) throws Exception {
    RatpackServer.start { spec ->
      spec.registry(
        Guice.registry { r ->
          r.bind(MyService.class)
        }
      )
      .handlers { chain ->
        chain.get { ctx ->
          MyService myService = ctx.get(MyService.class)
          myService.myMethod()
          ctx.render("Finished!")
        }
      }
    }
  }
}

@ilopmar
Copy link
Author

ilopmar commented Dec 15, 2015

Excellent! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment