Questions tagged [cake-pattern]

The cake pattern is a Scala dependency injection solution that uses only native language features, without any framework support.

The cake pattern is a Scala dependency injection solution that uses only native language features, without any framework support.

References:

73 questions
0
votes
0 answers

How to enforce encapsulation with the Cake Pattern

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…
Augusto
  • 28,839
  • 5
  • 58
  • 88
0
votes
1 answer

Scala Cake Pattern: How to avoid Dependency Collisions?

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…
simou
  • 2,467
  • 4
  • 30
  • 39
0
votes
1 answer

Initializing a trait attribute while using the cake patern

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 { …
Adrian
  • 3,762
  • 2
  • 31
  • 40
0
votes
1 answer

How to avoid lazy vals when using cross dependent traits in cake pattern without additional traits

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…
samthebest
  • 30,803
  • 25
  • 102
  • 142
0
votes
2 answers

Mockito ignores my Specs2 sugared verify steps when traits are involved

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…
flurdy
  • 3,782
  • 29
  • 31
0
votes
0 answers

Cake Pattern self-type annotation vs. stub def or val

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…
netta
  • 508
  • 6
  • 16
0
votes
1 answer

Abstract fields for dependency injection

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…
James Davies
  • 9,602
  • 5
  • 38
  • 42
0
votes
2 answers

Scala cake pattern with Existential Types: compile error

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) =…
damirv
  • 125
  • 1
  • 5
0
votes
1 answer

Junits using Mocks scala traits and cake pattern

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…
user1822249
  • 727
  • 2
  • 8
  • 12
0
votes
1 answer

Replace only repositories on a global cake pattern application

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…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
0
votes
2 answers

Integration tests in Scala when using compagnons with Play2? -> Cake pattern?

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…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
0
votes
3 answers

Cake pattern, self: UserRepositoryComponent =>

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?
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
-1
votes
1 answer

cake pattern Scala

import scala.collection.mutable class Session trait SessionProvider: def session: Session trait DefaultSessionProvider extends SessionProvider: val dummySession = new Session override def session =…
Shaco
  • 1
  • 1
1 2 3 4
5