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
30
votes
5 answers

Cake pattern with Java8 possible?

I just wonder: with Java 8, and the possibility to add implementation in interfaces (a bit like Scala traits), will it be possible to implement the cake pattern, like we can do in Scala? If it is, can someone provide a code snippet?
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
25
votes
4 answers

Why use scala's cake pattern rather than abstract fields?

I have been reading about doing Dependency Injection in scala via the cake pattern. I think I understand it but I must have missed something because I still can't see the point in it! Why is it preferable to declare dependencies via self types…
Noel Kennedy
  • 12,128
  • 3
  • 40
  • 57
20
votes
3 answers

Can Scala's Cake Pattern be implemented in Haskell?

Using a number of newer language features in Scala it's possible to implement a composable component system and create components using the so called Cake Pattern, described by Martin Odersky in the paper Scalable Component Abstractions and also in…
tibbe
  • 8,809
  • 7
  • 36
  • 64
18
votes
1 answer

Scala Cake Pattern Encourage Hardcoded Dependencies?

I'm still trying to learn Scala's Cake Pattern. It seems to me that it gives you the advantage of centralizing your configuration of "Components" as well as the ability to provide default implementations for those components (which are of course…
shj
  • 1,558
  • 17
  • 23
12
votes
2 answers

Akka and cake pattern

I'm confused how to ensure that my Actors have the appropriate dependencies using the cake pattern. I'm still getting to grips with this, and I can't find any examples anywhere. I'm basically just looking for a tutorial/resource to follow. Cheers,…
Owen
  • 6,992
  • 7
  • 44
  • 77
11
votes
2 answers

Scala Slick Cake Pattern: over 9000 classes?

I'm developing a Play! 2.2 application in Scala with Slick 2.0 and I'm now tackling the data access aspect, trying to use the Cake Pattern. It seems promising but I really feel like I need to write a huge bunch of classes/traits/objects just to…
user1498572
  • 533
  • 1
  • 6
  • 15
11
votes
5 answers

Scala Cake Pattern and Dependency Collisions

I'm trying to implement dependency injection in Scala with the Cake Pattern, but am running into dependency collisions. Since I could not find a detailed example with such dependencies, here's my problem: Suppose we have the following trait (with 2…
orrsella
  • 307
  • 1
  • 2
  • 7
10
votes
2 answers

Scala cake pattern for objects with different lifetimes

I tried to use cake pattern in my project and liked it very much, but there is one problem which bothers me. Cake pattern is easy to use when all your components have the same lifetime. You just define multiple traits-components, extend them by…
Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
8
votes
1 answer

How can I use Scala's cake pattern to implement robot legs?

My development makes extensive use of the robot legs binding problem. I know how to solve it with PrivateModule in Guice, but it isn't clear how this would be done with Scala's cake pattern. Could someone explain how this would be done, ideally…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
8
votes
2 answers

How to use mocks with the Cake Pattern

I have the following class: class LinkUserService() { //** cake pattern ** oauthProvider: OAuthProvider => //****************** def isUserLinked(userId: String, service: String) = { val cred = oauthProvider.loadCredential(userId) …
ThaDon
  • 7,826
  • 9
  • 52
  • 84
8
votes
1 answer

Cake pattern with overriding abstract type don't work with Upper Type Bounds

I want to override abstract type in trait with <: and not with = (like answer here Scala Upper Bounds : value is not a member of type parameter). I want to use cake pattern, but this doesn't work, i don't understand why ? trait A { def ping =…
reyman64
  • 523
  • 4
  • 34
  • 73
7
votes
2 answers

Cake pattern w/ akka: Providing implicit actorSystem to several layers

I'm currently baking my first cake pattern, so please bear with me. I took my working monolithic app and I cutted it into functional layers. The cut looks clean but resulted in two of the layers that depend on an implicit ActorSystem. I tried to…
maasg
  • 37,100
  • 11
  • 88
  • 115
7
votes
2 answers

Usefulness of explicitly-typed self references in the Cake Pattern

It seems that the most common use of Scala's explicitly-typed self references is in the "Cake pattern," in which a module's dependencies are declared like: class Foo { this: A with B with C => // ... } In general, ignoring the cake pattern for a…
mergeconflict
  • 8,156
  • 34
  • 63
6
votes
1 answer

cake pattern - why is it so complicated

I am trying to learn about the cake pattern. I am reading this blog about it. The example code from that blog is: case class User (name:String,email:String,supervisorId:Int,firstName:String,lastName:String) trait UserRepository { def get(id:…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
6
votes
3 answers

importance of cake pattern in scala

I have started learning scala for a while now and now looking at cake pattern. I got the example from here trait UserRepositoryComponent { def userLocator: UserLocator trait UserLocator { def findAll: List[User] } } trait…
Sajith Silva
  • 823
  • 1
  • 13
  • 24
1
2 3 4 5