Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing DI in application written in Scala and Java - is it possible in "Scala way" - without additional framework?
    primarykey
    data
    text
    <p>I have an application written partially in Java and Scala. In case of Scala code I want to use scala features to make dependency injection. In old Java code spring was used i.e. to inject services beans to wicket pages etc. In scala code I use selfless trait pattern to create services as described here: <a href="http://www.artima.com/scalazine/articles/selfless_trait_pattern.html" rel="nofollow">http://www.artima.com/scalazine/articles/selfless_trait_pattern.html</a></p> <p>Dependency injection in scala is done currently using "Configuration" object which wires everything together:</p> <pre><code>scala&gt; trait Friendly { | def greet() { println("hi there") } | } defined trait Friendly scala&gt; object Friendly extends Friendly defined module Friendly scala&gt; object ServiceConsumer { | def myService: Friendly = myServiceInjected.getOrElse(throw new RuntimeException("dependency not injected")) | var myServiceInjected: Option[Friendly] = None | } defined module ServiceConsumer scala&gt; class ServiceConsumer { | def callService() { | ServiceConsumer.myService.greet() | } | } defined class ServiceConsumer scala&gt; object Configuration { | def init() { | ServiceConsumer.myServiceInjected = Some(Friendly) | } | } defined module Configuration scala&gt; Configuration.init scala&gt; val c = new ServiceConsumer c: ServiceConsumer = ServiceConsumer@292e2fba scala&gt; c.callService() hi there </code></pre> <p>But how to use "Friendly" service from Java class? Should I still use Spring? How to publish Friendly service written in Scala as a Spring bean? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload