Skip to content

Commit

Permalink
update docs: ResourceInfo binding mention, hk bridge configuration gu…
Browse files Browse the repository at this point in the history
…ide, fix todos
  • Loading branch information
xvik committed Mar 29, 2017
1 parent bb421ba commit 681f014
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/doc/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ These bindings are not immediately available as HK context [starts after guice](
Request-scoped bindings:

* `javax.ws.rs.core.UriInfo`
* `javax.ws.rs.container.ResourceInfo`
* `javax.ws.rs.core.HttpHeaders`
* `javax.ws.rs.core.SecurityContext`
* `javax.ws.rs.core.Request`
Expand Down
1 change: 1 addition & 0 deletions src/doc/docs/guide/bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ These bindings available after HK context start:
Request-scoped bindings:

* `javax.ws.rs.core.UriInfo`
* `javax.ws.rs.container.ResourceInfo`
* `javax.ws.rs.core.HttpHeaders`
* `javax.ws.rs.core.SecurityContext`
* `javax.ws.rs.core.Request`
Expand Down
22 changes: 22 additions & 0 deletions src/doc/docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@ Then configuration could be injected by interface:
By default, configuration is bound only for [all classes in hierarchy](bindings.md#configuration). In example above it would be
`Configuration` and `MyConfiguration`.

### HK bridge

If you need HK services be able to use guice beans, then [hk bridge](https://hk2.java.net/2.4.0-b34/guice-bridge.html)
must be activated.
This may be useful when some services are managed by HK (e.g. with [@HK2Managed](lifecycle.md#problematic-cases)).

To activate bridge:

* Add dependency: `org.glassfish.hk2:guice-bridge:2.5.0-b32` (version must match HK version, used by dropwizard)
* Enable option: `#!java .option(GuiceyOptions.UseHkBridge, true)`

After that, HK beans could inject guice beans:

```java
@HK2Managed
public class HkService {

@Inject
private GuiceService service;
}
```

## Diagnostic

Enable configuration [diagnostic console logs](diagnostic.md) to diagnose configuration problems:
Expand Down
4 changes: 2 additions & 2 deletions src/doc/docs/guide/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Anyway, it is not always possible to hide integration details, especially if you
* [Managed beans](../installers/managed.md) started
* **HK2 context creation**
* `GuiceFeature` (registered earlier) called
* Register [hk2-guice bridge](https://hk2.java.net/2.4.0-b34/guice-bridge.html) (only guice to hk way to let hk managed beans inject guice beans)
* [Optionally](configuration.md#hk-bridge) register [hk2-guice bridge](https://hk2.java.net/2.4.0-b34/guice-bridge.html) (only guice to hk way to let hk managed beans inject guice beans)
* Run jersey specific installers ([resource](../installers/resource.md), [extension](../installers/jersey-ext.md))

!!! note
Expand Down Expand Up @@ -120,6 +120,6 @@ There are two options to solve this:

* use `@LazyBinding`: bean instance will not be created together with guice context (when `MultivaluedParameterExtractorProvider` is not available),
and creation will be initiated by HK, when binding could be resolved.
* or use `@HK2Managed` this will delegate instance management to HK, but still guice specific extensions may be used.
* or use `@HK2Managed` this will delegate instance management to HK, but still guice services [may be injected](configuration.md#hk-bridge).

In other cases simply wrap jersey specific bindings into `Provider`.
2 changes: 1 addition & 1 deletion src/doc/docs/installers/jersey-ext.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Detects classes annotated with jersey `@javax.ws.rs.ext.Provider` annotation an
!!! attention ""
Extensions registered as **singletons**, even if guice bean scope isn't set.

Due to specifics of HK integration (TODO link), you may need to use:
Due to specifics of [HK integration](lifecycle.md), you may need to use:

* `#!java @HK2Managed` to delegate bean creation to HK
* `#!java @LazyBinding` to delay bean creation to time when all dependencies will be available
Expand Down
4 changes: 2 additions & 2 deletions src/doc/docs/installers/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SampleResource {
}
```

// todo link to jersey binidngs
See [jersey objects, available for injection](../guide/bindings.md#jersey-specific-bindings).

## @Context usage

Expand Down Expand Up @@ -121,7 +121,7 @@ public class MyResource {
## HK2 managed resource

If resource class is annotated with `#!java @HK2Managed` then jersey HK container will manage bean creation instead of guice.
Injection of guice managed beans will still be possible via registered [hk2-guice-bridge](https://hk2.java.net/2.4.0-b34/guice-bridge.html),
Injection of guice managed beans [could still be possible](../guide/configuration.md#hk-bridge) via registered [hk2-guice-bridge](https://hk2.java.net/2.4.0-b34/guice-bridge.html),
but guice aop features will not work.

```java
Expand Down

0 comments on commit 681f014

Please sign in to comment.