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
3
votes
2 answers

Cake Pattern: How to share an instance?

I have a configuration component in my Scala project. Obviously I don't want to have more than one instance of this component. I'm using the cake pattern, but I'm not sure how to tweak it to fit my requirements: // Library //…
stephanos
  • 3,319
  • 7
  • 33
  • 47
3
votes
1 answer

Cake pattern: how to get all objects of type UserService provided by components

This question may help you understand my needs. Cake pattern: one component per implementation, or one component per trait? I have a Scala application using multiple UserService implementations which will be provided by component(s?). I wonder if…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
2
votes
2 answers

How to keep single responsibility when using self-type in Scala?

Using self-type for dependency injections, cause to expose public method of other traits ,which break the single responsibility principal. Let's me talk with example trait Output { def output(str: String): Unit } trait ConsoleOutput extends…
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
2
votes
0 answers

Scala self type alias name overriding fields issue

I've encountered a problem when self type alias name 'overrides' extended class field and compiler doesn't indicate it. My scenario with akka actors: class MyActor extends Actor { self: SomeModuleInjection => ... someActorRef ! SomeMessage …
2
votes
2 answers

Scala Cake Pattern & Self Type Annotations

I'm trying to follow the example from this blog. I understand the example but having trouble implementing it. trait Database { // ... } trait UserDb { this: Database => // ... } trait EmailService { this: UserDb => // Can only access…
Killyz
  • 109
  • 2
  • 9
2
votes
2 answers

Scala Generic Subtypes and Cake Pattern

I have the following class hierarchy: abstract class Event(val timeStamp:Long,val id:Long ) case class StudentEvent(override val timeStamp:Long, override val id:Long, firstName:String,lastName:String) extends Event(timeStamp,id ) case…
danny.lesnik
  • 18,479
  • 29
  • 135
  • 200
2
votes
2 answers

Cake pattern nested traits

Why everyone is using this form of definition: trait UserServiceComponent { def userService: UserService trait UserService { def findAll: List[User] def save(user: User) } } Instead of that: trait UserService { def findAll:…
Dmitry Golubets
  • 570
  • 5
  • 13
2
votes
1 answer

Abstracting the Database client in the cake pattern

I am trying to create an abstraction for a SearchService using the Cake pattern. This is what I have currently: trait SearchServiceComponent{ val searchService:SearchService trait SearchService{ def searchForSomething(..):List[String] …
sc_ray
  • 7,803
  • 11
  • 63
  • 100
2
votes
1 answer

Is scala's cake pattern possible with parametrized components?

Parametrized components work well with the cake pattern as long as you are only interested in a unique component for each typed component's, example: trait AComponent[T] { val a:A[T] class A[T](implicit mf:Manifest[T]) { println(mf) …
Nicolas
  • 277
  • 5
  • 13
1
vote
0 answers

Cake Pattern & Akka = Serialization issues?

Problem: I have used the cake pattern to build a system of components (traits) which define a family of types and specialise them covariantly (cf., family polymorphism). Then I have defined a component which defines some actors and messages to be…
metaphori
  • 2,681
  • 1
  • 21
  • 32
1
vote
1 answer

illegal inheritance; self-type .... does not conform to

I am trying to implement a cake pattern like code, but I get: Error:(47, 36) illegal inheritance; self-type app.server.im.Im_Api_Service_Impl.type does not conform to app.server.im.Persistence[app.server.im.State.State]'s selftype…
jhegedus
  • 20,244
  • 16
  • 99
  • 167
1
vote
1 answer

Is it possible to use cake pattern based DI for components provided by Play framework?

I have seen a couple of posts related to DI using cake pattern. One of them being http://jonasboner.com/real-world-scala-dependency-injection-di/ shared by one of my colleagues. But If I need to use say WSClient from Play 2.5, can I get hold of…
1
vote
2 answers

Scala Slick single filter for multiple TableQuery instances

I'm using Scala Slick-3.1.0 lib. How is it possible to make a generic Slick filter function that takes TableQuery instance as an input and makes same slick filter on it? I have several case classes (two for example) representing data stored in…
aaamarkin
  • 11
  • 5
1
vote
0 answers

Display graph of trait dependency for heavily cake pattern scala and sbt program

Before i try to make a manual graph of dependency (using inkscape) to resume all possibility for my scala program which use heavily cake pattern, i ask question here. Is there a best and simple way to automaticaly cartography a complex hierarchy of…
reyman64
  • 523
  • 4
  • 34
  • 73
1
vote
1 answer

Cake Pattern in Scala

I was trying to convert my understanding about cake patterns in to simple scala code and found out that its not compiling. Could some one please have a look at the below code and tell me whats the problem in the way I understand the patterns? I read…
Anand
  • 601
  • 2
  • 7
  • 17