Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Răzvan Rotaru
    @roti
    @quanghieple Play uses Guice by default for dependency injection. And Guice recommends constructor injection over field injection. (see https://github.com/google/guice/wiki/Injections#field-injection). I guess it's ok if you have no other choice. I don't know if field injections work when the field is declared in a trait, but that can be found out easily. :)
    let me know if it works, I'm curious
    what exactly you want to be explained in the code? why conf is null in the constructor?
    Răzvan Rotaru
    @roti
    and if field injection does not work in a trait you have two options:
    1. find out why, it could be due to the way scala compiles traits (if you are on play 2.4, you are on a very old scala version, 2.10), or it may be because guice does not support it (though I don't see why that would be the case)
    2. programatically ask guice for an instance, instead of the @Inject annotation.
    7 replies
    quanghieple
    @quanghieple
    @roti thank you for the answer
    Matias Partanen
    @mpartan
    I'm setting up a new Play project as of recent that would interact with Azure using few libraries (e.g. servicebus, cosmos). It seems the newest version of Play is depending on Jackson 2.10, while most Azure client libraries depend on 2.11, which was released last April. I'm just wondering about options I have for an approach, and what I might be missing, for instance
    • Use older com.azure.cosmos/servicebus libraries that depend on 2.10., and migrate to newer with Play 2.9 (?) release and Jackson 2.11. (?) support when it comes. It seems that Akka is depending on that Jackson 2.10 version though, and Akka hasn't released Jackson 2.11. support
    • Fork Azure libraries and downgrade the Jackson on core, then build custom versions and use those as dependencies (if even possible)
    • Try with dependencyOverrides in build.sbt to force Jackson 2.10, hope there won't be any incompatibilities or NoClassDefFounds later
    • Skip using Azure libraries altogether, try some REST-based solution where applicable
    • Skip using Play for this project altogether, use some other Framework and Azure libraries with Jackson 2.11.
    • Something else I'm not thinking about? :)
    2 replies
    Răzvan Rotaru
    @roti
    @mpartan dependency resolution in most platforms (Scala and Java included) is a mess. I guarantee you in many cases, if not most cases, you are not using the library version you think you use. This problem is controllable only in small projects. Once you reach a certain size, it's really more of a "click and pray" approach. The good news is that it works most of the time (in my experience), and problems tend not to occur that often (but when they do, it's a nightmare). My approach has always been to pay attention to my own dependencies (either align the versions to the ones used by the framework, or use the latest ones), and worry about such conflicts only when a problem occurs.
    In your case it's actually quite easy. First jackson 2.11 is very likely to be compatible with 2.10, and it's also easy to find out.
    Răzvan Rotaru
    @roti
    My question would be how did you come to this issue? Don't you have other libraries that are in the same situation?
    Răzvan Rotaru
    @roti
    I would go for dependencyOverrides or letting the build system to select a Jackson version (preferring the latter, because dependencyOverrides introduces manual maintenance of library versions). And in the worst case scenario, if it really doesn't work, you can always compile play with the desired Jackson version.
    Matias Partanen
    @mpartan
    Build compiles with different dependencies, but ScalaModule in throws explicit error: https://github.com/FasterXML/jackson-module-scala
    [error] com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.10.5 requires Jackson Databind version >= 2.10.0 and < 2.11.0
    [error]     at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:61)
    2 replies
    So probably has to be explicit dependencyOverride
    Jeremias Kuitunen
    @defic

    I am upgrading from play 2.6 to 2.7.8, and I get this error

    ControllerComponents not set! Call setControllerComponents or create the instance with dependency injection.

    Even though my controller is extending InjectedController and in 2.6 it works fine. With Base-/AbstractController it works, but I rather not have the boilerplate. I couldn't find any existing issues about this

    Jeremias Kuitunen
    @defic
    Nvm, I changed play version to 2.7.9 and now it is working fine
    Matias Partanen
    @mpartan

    My question would be how did you come to this issue? Don't you have other libraries that are in the same situation?

    This is a new project and this is the first library to trigger the situation (e.g. uses Jackson 2.11)

    Răzvan Rotaru
    @roti
    can I get an instance of CacheApi without dependency injection (in Play 2.6)?
    Henri Cook
    @henricook
    Hi everyone! I feel like something really simple is missing from the docs. How can I instantiate something when starting my Play Framework application? I want to initialise Sentry and just need to call Sentry.init as early as possible
    Igmar Palsenberg
    @igmar
    Bind an eager singleton in a module
    Henri Cook
    @henricook
    Nice, i'll look into it thanks
    i'm also just seen sentry-logback which might be a good path to go down
    Alexis Hernandez
    @AlexITC
    @henricook instead of calling sentry manually, just use the sentry-logback integration, this project uses that (just do git log | grep sentry)
    Alexandre Roba
    @AlexandreRoba
    @mn98 Two books from Denis Kalinin, "Modern web development with Scala" and "Practical event sourcing with scala". Very hands on books.
    Leandro Rodrigo Saad Cruz
    @leandrocruz
    Hey guys. I wonder if this is a configuration issue, but when I respond with Ok.withCookies(Cookie("one"), Cookie("two")) the http client (curl and chrome) show only on set-cookie header. Any pointers?
    I'm running play 2.8.7
    Leandro Rodrigo Saad Cruz
    @leandrocruz
    Has the same problem with Result.discardingCookies()
    Leandro Rodrigo Saad Cruz
    @leandrocruz
    I tried to get around the issue by adding multiple 'set-cookie' headers to my response, but it didn't work. AFAIK, play makes an exceptional case for cookies, but I don't think it is working
    Jeremias Kuitunen
    @defic

    I updated play from 2.5.9 to 2.7 and need to convert classes to work with DI. I am having trouble migrating the custom logback appender that sends logs to external service with wsclient. I get this error when starting the server:
    ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type service.logging.LogstashAppender
    And this is the signature of that class:

    @Singleton
    class LogstashAppender @Inject()(ws: WSClient) {

    Back in play 2.5 it worked without DI as I just sent the logs with play.current.WS

    But the play.api.current was removed since everything needs to be DI. How can I work around this?
    Jeremias Kuitunen
    @defic
    Is it possibly to add appender programmatically to play logback?
    Leandro Rodrigo Saad Cruz
    @leandrocruz

    Hey guys. I wonder if this is a configuration issue, but when I respond with Ok.withCookies(Cookie("one"), Cookie("two")) the http client (curl and chrome) show only on set-cookie header. Any pointers?

    Any help? What am I missing?

    Răzvan Rotaru
    @roti
    @leandrocruz I would try to find out in a debug session looking into play's source code.
    Leandro Rodrigo Saad Cruz
    @leandrocruz
    Found the issue @roti
    a proxy in the middle which removed the header
    thanks!
    Joe Netti
    @nettijoe96
    Hi folks! Anyone knowledgeable with Swagger and play integration? I've been stuck on a specific problem for a bit...
    (specifically swagger doesn't seem to pick up scala enumerations)
    Dheeraj Karande 🇮🇳
    @dheerajkarande_twitter
    @all is there any way to access attributes defined inside app conf into logback.xml
    Will Sargent
    @wsargent
    yes
    play.logger.includeConfigProperties=true
    play.logger.includeConfigProperties=true
    play.logger.includeConfigProperties=true will do it
    Dheeraj Karande 🇮🇳
    @dheerajkarande_twitter
    @wsargent thanks a lot
    NKM
    @nkmittal
    How can I get data in a TrieMap directly with Anorm when using a SQL SELECT query ? I want to make username as the key and rest of the parameters in a case class value. The expected response from DB query is multiple rows of the table.
    Michael
    @michbarsinai
    Seed project announcement: Our seed project for simple, self contained sites (PSPS) has been updated (Play 2.8, Scala 2.13, Bootstrap5, and many other nice things). All are invited to use, fork, pull-request, comment, etc. https://github.com/codeworth-gh/PSPS :-)
    kyle tilman
    @ktilcu
    Hey firends! I'm trying to mock a response from a 3rd party API and I'm running into a problem generating the output this api generates. Specifically, it stringifies json 2 times. so instead of {"omg:":"json"} we are trying to create "{\"omg\":\"json\"}". Any thoughts on how to do that since Json.stringify wants a JsValue?
    Alexis Hernandez
    @AlexITC
    I have one example for mocking requests to 3rd party services
    kyle tilman
    @ktilcu
    Thanks @AlexITC ! I'm les concerned about the mocking and more interested in how to create a double stringified JsObject
    Alexis Hernandez
    @AlexITC
    doesn't Json.stringify(JsString(Json.stringify(value))) work?