///////////////////////////////////////////////////////////////
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
///////////////////////////////////////////////////////////////

[[lang-scala, Scala Library]]
= Scala Support =

[devstatus]
--------------
source=libraries/lang-scala/dev-status.xml
--------------

The Scala Support Library allows Fragments and Composites to be written as Scala traits.

include::../../build/docs/buildinfo/artifact.txt[]

The Scala Support Library is a Generic mixin class that implements  Composites by delegating to Scala traits.


== Composition ==

Example mixin declaration:
[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldMixin2.scala
tag=mixin
----

Example composite declaration:
[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldComposite.scala
tag=composite
----

Example typed concern:
[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloThereConcern.scala
tag=typedconcern
----

Example generic concern with filter:
[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/ExclamationGenericConcern.scala
tag=genericconcern
----

And the assembly code.
Note that the `ScalaTraitMixin` must be added.
[snippet,java]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
tag=composite
----

That pretty much covers the domain model part.
Usage from Java is transparent, since it looks just like interfaces and classes.


== Entity composites ==

The following example separate between command interface (suggestions to change), events (after the fact), and data, so they are in three separate traits below.
Only commands are called by client code.

[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestEntity.scala
tag=entity
----

The `self` operator thing solves the `@This` injection requirements, although it doesn't do private injections (i.e. the Entity *has* to extend Events and Data for it to work).

Everything is statically typed.

And the corresponding assembly code:

[snippet,java]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
tag=entity
----


== Services composites ==

The following example is a pretty simple service written as a Scala trait:

[snippet,scala]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/TestService.scala
tag=service
----

And the corresponding assembly code:

[snippet,java]
----
source=libraries/lang-scala/src/test/scala/org/qi4j/sample/scala/HelloWorldCompositeTest.java
tag=service
----
