
=== Weld

1) Add Weld dependency to your project:

[dependency, artifactId="jooby-weld"]
.

2) Install Weld:

.Installing Weld
[source, java, role = "primary"]
----
import io.jooby.di.WeldModule;
import static io.jooby.Jooby.runApp;

public class App extends Jooby {

  {
    install(new WeldModule());                      <1>
      
    get ("/", ctx -> {
      MyService service = require(MyService.class); <2>
      service.doSomething();
    });
  }

  public static void main(String[] args) {
    runApp(args, App::new);
  }
}
----

.Kotlin
[source, kotlin, role = "secondary"]
----
import io.jooby.di.WeldModule
import io.jooby.runApp

fun main(args: Array<String>) {
  runApp(args) {
    install(WeldModule())                           <1>

    get ("/") {
      val service = require(MyService::class)       <2>
      service.doSomething()
    }
  }
}
----

<1> Install Weld
<2> The javadoc:Jooby[require, java.lang.Class] call is now resolved by Weld

==== Property Injection

Configuration properties can be injected using the `@Named` annotation:

.application.conf
[source, bash]
----
currency = USD
----

.Java
[source,java,role="primary"]
----
import javax.injext.Inject;
import javax.injext.Named;

public class BillingService {

  @Inject
  public BillingService(@Named("currency") String currency) {
    ...
  }

}
----

.Kotlin
[source,kotlin,role="secondary"]
----
import javax.injext.Inject
import javax.injext.Named

class BillingService @Inject constructor(@Named("currency") currency: String) {
  ...
}
----

==== MVC routes

The Weld extension does a bit more in relation to MVC routes:

- A MVC route annotated with the javadoc:annotations.Path[] annotation is
automatically registered. No need to register it manually

- The default scope is `prototype` (creates a new instance per request). If you prefer a single 
instance add the `javax.inject.Singleton` annotation

.MVC route
[source, java, role="primary"]
----
import io.jooby.annotations.*;

@Path("/")
public class Hello {

   @GET
   public String sayHi() {
     return "Hi Weld!";
   }
}
----

.Kotlin
[source, kotlin, role="secondary"]
----
import io.jooby.annotations.*;

@Path("/")
class Hello {

   @GET
   fun sayHi(): String {
     return "Hi Weld!"
   }
}
----
