I've been reading a bit about the Cake Pattern in Scala (I know that is old stuff), and I cannot see or imagine an way to lock down the concrete classes, so dependencies don't leak from the classes where they are injected.
A simple and current…
My question is very similar to Scala Cake Pattern and Dependency Collisions. But I'm struggling to find a concrete solution as suggested in Daniel C's answer.
So here is the problem:
A ProductDetailsPage (trait) requires two independent service…
Is it possible to initialize an attribute in an enclosed trait of a cake pattern? Something similar to early initializers. For example:
object CakePatternInit {
trait A {
var prop: String = null
}
trait A1 extends A
trait B {
…
Suppose we have
scala> trait A { val y: Int; val x = 1; val y2 = y + 1 }
scala> trait B { val y: Int = 1; val x: Int; val x2 = x + 1 }
scala> class C extends A with B
Then both y2 and x2 should end up with value 2 in C. Now if we mixin A then B…
Normally Specs2 sugared Mockito verifications are checked and fails the test when appropriate. However in some instances they are ignored.
Normally this test verification fails as expected as myApp called myService at least once.
import…
When using the cake pattern, when would you want to use the self-type annotation eg:
trait DefaultFoo extends Foo {
this: Bar =>
...
}
vs a stub def
trait DefaultFoo extends Foo {
def bar:Bar
...
}
or a stub val
trait DefaultFoo extends…
In Scala, is there there anything wrong with using the below method of dependency injection.
// Define an interface
trait FileStorage {
def readFile(filename:String):OutputStream
}
// And an implementation
class S3FileStorage extends FileStorage…
Through this question, I found this article on the 'config' pattern from Precog. I tried this with two modules:
case class Pet(val name: String)
trait ConfigComponent {
type Config
def config: Config
}
trait Vet {
def vaccinate(pet: Pet) =…
I have a scala trait as follows -
trait Mytrait {
def saveData : Boolean = {
//make database calls to store
true
}
def getData : Integer = {
//get data from database
return i
}
}
Now I have heard about…
I'm trying to use the cake pattern for the first time.
I kind of understand how it works, but would like to know if it is possible to mix already mixed traits or something like that.
What I would like is to build a global application with the cake…
I'm working on my first Scala application, where we use an ActiveRecord style to retrieve data from MongoDB.
I have models like User and Category, which all have a companion object that uses the trait:
class MongoModel[T <: IdentifiableModel with…
I'm trying to understand the cake pattern.
I found this gist:
https://gist.github.com/2127745
But I don't understand this syntax:
// Explicit dependency on User Repository
self: UserRepositoryComponent =>
Can someone explain it please?