inject ServletContext into controller

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

inject ServletContext into controller

psfung
I use the annotation framework to instantiate resource controllers. My controller depends on a bean in ServletContext. How to inject it? Does this work in Milton?

@ResourceController
public class MyController {
  @Inject
  private ServletContext context;
  ...
}
Reply | Threaded
Open this post in threaded view
|

Re: inject ServletContext into controller

bradmacnz
Sorry, Milton doesnt provide a dependency injection framework.

However, the milton ServletRequest object contains a servletContext
property, so you can get the servletContext anywhere you have a request.

You can get a Request either by adding it to annotated methods, or
statically from HttpManager.request(), and then casting it to ServletContext

/Brad


On 18/08/16 15:54, psfung wrote:

> I use the annotation framework to instantiate resource controllers. My
> controller depends on a bean in ServletContext. How to inject it? Does this
> work in Milton?
>
> @ResourceController
> public class MyController {
>    @Inject
>    private ServletContext context;
>    ...
> }
>
>
>
>
> --
> View this message in context: http://milton-users.96038.n3.nabble.com/inject-ServletContext-into-controller-tp4025978.html
> Sent from the Milton Users mailing list archive at Nabble.com.
> _______________________________________________
> Milton-users mailing list
> [hidden email]
> http://lists.justthe.net/mailman/listinfo/milton-users

_______________________________________________
Milton-users mailing list
[hidden email]
http://lists.justthe.net/mailman/listinfo/milton-users