align-toparrow-leftarrow-rightbackbellblockcalendarcamerachatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-crosscrosseditfacebookglobegoogleimagesinstagramlocation-pinmagnifying-glassmailmoremuplabelShape 3 + Rectangle 1outlookpersonplusImported LayersImported LayersImported Layersshieldstartwitteryahoo

Re: [lsug] Dependency Injection

From: Noel K.
Sent on: Thursday, February 14, 2013 5:03 PM
Classes aren't as composable as traits (you can't mixin two classes but you can mixin two traits).  Traits can't take constructor parameters.

You could simulate your approach with traits with abstract fields, or by overriding implemented fields but you might as well use cake (this is what we did)



On 14 Feb 2013, at 16:40, Ryan LeCompte <[address removed]>

Can you give an example of your "implicitly only" lightweight approach? It sounds very compelling. Also, what's wrong with a simple approach where your dependencies are concrete constructor parameters (not implicit), but they have default values to make the construction easier on the user? This is what we use in the Ruby world and it works well. :-)


On Feb 14, 2013, at 8:31 AM, Alois Cochard <[address removed]> wrote:

Hi Sandro,

Thanks for your interest :)

As I said in my original message the website is outdated and refer to sindi 0.5 which was using a compiler plugin (current version is 1.0-RC3 and is implemented with implicits), I should update it but haven't found time yet to do so :-s

I plan to add a simple app example, as test don't really show how to integrate it concretely in an application, the approach I generally take:

class Bar
class Foo(bar: Bar) {
   def run = println("hello world")

trait ApplicationContext {
   implicit val bar = bind(new Bar) // manually creating instance
   implicit val foo = bind(autowire[Foo]) // using autowiring to inject construtor parameter

object App extends ApplicationContext {

Hope that help getting started ;)


On 14 February[masked]:16, Sandro Mancuso <[address removed]> wrote:
Hi Alois

Thanks for your email. 

I'm having problems to look at the documentation / examples:

I'm also getting a 404 when looking at the examples:

I'll definitely have a closer look at it soon. 

Many thanks and good luck with the project. 

From: Alois Cochard <[address removed]>
To: [address removed]
Sent: Thursday, 14 February 2013, 15:59
Subject: Re: [lsug] Dependency Injection

Hi Sandro,

You might be interested in

Which I am the auther, doc on the website aren't updated for last version but there is some nice tests: 

Sindi isn't intrusive, and guarantee your types to be bound at compile time vs runtime thanks to implicitis resolution, and using autowiring (that use macro in 2.10) you can avoid good bunch of boilerplates.

I'm a bit skeptic about cake pattern in large project as this introduce a good bunch of complexity with path dependent type, even if some technic shown recently by Daniel Spiewak and Debasish Gosh that use existential type enable to work around issue introduced by path dependent type, I still find it very boilerplaty

For small scale project cake/reader monad might be well suited.

In one of my personal project I started recently I try to do it using implicits without even using Sindi, I'm not sure it will scale well outside of utilities libraries... time will tell ;)

May the Force be with you,

Alois Cochard

On 14 February[masked]:51, Sandro Mancuso <[address removed]> wrote:
Hi all

We are starting a project with Scala but none of us are very experienced with it. 

We were looking for ways to do dependency injection and we found the following:

Cake pattern:


We also find a few dead repositories on github but nothing very relevant. 

I was wondering what you guys are using of DI in Scala. Pros and Cons?

Maybe because of my lack of experience in Scala, I found the Cake Pattern a bit verbose and SubCut a bit intrusive since I need to add SubCut stuff to all my classes. At least, that was my impression when reading the tutorial. 

Any views?

Sandro Mancuso
Founder of the London Software Craftsmanship Community

Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Ryan LeCompte ([address removed]) from London Scala Users' Group.
To learn more about Ryan LeCompte, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]


This message, together with any attachments, is intended for the stated addressee(s) only and may contain privileged or confidential information. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Royal Veterinary College (RVC). If you are not the intended recipient, please notify the sender and be advised that you have received this message in error and that any use, dissemination, forwarding, printing, or copying is strictly prohibited. Unless stated expressly in this email, this email does not create, form part of, or vary any contractual or unilateral obligation. Email communication cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, amended, lost, destroyed, incomplete or contain viruses. Therefore, we do not accept liability for any such matters or their consequences. Communication with us by email will be taken as acceptance of the risks inherent in doing so.

Our Sponsors

  • Scala Dojo

    Web site for monthly Scala Dojo

  • Scala Jobs

    Google Group of Scala Jobs in the London Area

  • Scalar Conf

    16 April 2016 in Warsaw, Poland

  • _.underscore

    Scala consultants, trainers, and developers, based in London, UK

  • Springer

    Help and supporters of the monthly dojo

  • Skills Matter

    Provide the venue for many of our meetings.

  • Mind Candy

    Help with the Adv Scala Meet-up

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy