Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. So what do you think of dependency injection?

So what do you think of dependency injection?

Scheduled Pinned Locked Moved The Lounge
discussioncsharpjavacomhelp
31 Posts 20 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Henry Minute

    Marc Clifton wrote:

    dependency injection (DI)

    Is that when children that you thought had fled the nest for good, pay a surprise visit.

    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

    M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #7

    Henry Minute wrote:

    Is that when children that you thought had fled the nest for good, pay a surprise visit.

    Nah, that's just the visitor pattern, when they consume everything in your refrigerator. Dependency Injection is when they move in after losing their job or getting a divorce (along with child dependencies, often enough). Marc

    Will work for food. Interacx

    H 1 Reply Last reply
    0
    • M Marc Clifton

      I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

      Will work for food. Interacx

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #8

      They've always struck me as symptomatic of the "Java way" - if a Java programmer's seen a design pattern they didn't like, it's news to me :-) I would rather pass an interface pointer (or a functor - you don't always need a whole interface) than rely on a big old library and configuration files. But then I've long had an affinity for functional programming[^].

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      X Z 2 Replies Last reply
      0
      • S Stuart Dootson

        They've always struck me as symptomatic of the "Java way" - if a Java programmer's seen a design pattern they didn't like, it's news to me :-) I would rather pass an interface pointer (or a functor - you don't always need a whole interface) than rely on a big old library and configuration files. But then I've long had an affinity for functional programming[^].

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        X Offline
        X Offline
        Xiangyang Liu
        wrote on last edited by
        #9

        Stuart Dootson wrote:

        They've always struck me as symptomatic of the "Java way" - if a Java programmer's seen a design pattern they didn't like, it's news to me

        Yeah, they also tend to write code that has every possible interface/factory you can think of, but no implementation of anything real.

        My .NET Business Application Framework My Home Page My Younger Son & His "PET"

        1 Reply Last reply
        0
        • R Roger Wright

          I'm with Jim - I don't like injections. Well, the morphine they gave me in the hospital was fun, but I still didn't like the needle much. All my dependencies are taken in drink.

          "A Journey of a Thousand Rest Stops Begins with a Single Movement"

          J Offline
          J Offline
          Jim Crafton
          wrote on last edited by
          #10

          Roger Wright wrote:

          All my dependencies are taken in drink.

          You need to write a design pattern that models that. Then, using some of the suggestions under Christopher's thread, market the whole thing to fame and fortune.

          ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh

          1 Reply Last reply
          0
          • M Marc Clifton

            Henry Minute wrote:

            Is that when children that you thought had fled the nest for good, pay a surprise visit.

            Nah, that's just the visitor pattern, when they consume everything in your refrigerator. Dependency Injection is when they move in after losing their job or getting a divorce (along with child dependencies, often enough). Marc

            Will work for food. Interacx

            H Offline
            H Offline
            Henry Minute
            wrote on last edited by
            #11

            Excellent!!

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            1 Reply Last reply
            0
            • M Marc Clifton

              I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

              Will work for food. Interacx

              M Offline
              M Offline
              Miszou
              wrote on last edited by
              #12

              If you want to talk to someone about CAB, Ward Bell[^] is the guy you need to talk to. Make sure you have plenty of time free though, because he is passionate about this stuff and will talk for days if you let him. :-D We've been using the Ideablade[^] DevForce "Classic" framework for a couple of years now and I've met Ward several times at various training sessions. He's a fascinating person to listen to and is very knowledgeable. Personally, I think a lot of the stuff he works on is a bit too academic for most of us in the real world, but it is certainly very interesting and thought-provoking nevertheless.

              The StartPage Randomizer - The Windows Cheerleader - Twitter

              1 Reply Last reply
              0
              • M Marc Clifton

                I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                Will work for food. Interacx

                P Offline
                P Offline
                peterchen
                wrote on last edited by
                #13

                I haven't understood why we need frameworks for that, and I am tired of the "how IoC can change your life" four color glossies. Is it really that complex?

                Don't attribute to stupidity what can be equally well explained by buerocracy.
                My latest article | Linkify!| FoldWithUs! | sighist

                1 Reply Last reply
                0
                • M Marc Clifton

                  I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                  Will work for food. Interacx

                  T Offline
                  T Offline
                  Todd Smith
                  wrote on last edited by
                  #14

                  I use it in my web projects and find it really useful. You could create a service manager but what about managing the lifetime of objects? That's where IoC really shines imho. The real fun comes from using IoC along with XML configuration so you can change things on the fly. You also have to recode and recompile your service manager anytime a constructor adds or removes a dependency. Another good feature is property injection. If a class needs logging all we have to do is add public ILogger Log {get; set;} and Log gets set by the IoC after construction. No need to change a constructor or worse 50 constructors for a complex hierarchy of objects just to add logging. In a 4teir application web application -> services -> repository -> data access layer what happens when your DAL needs your HttpContext? Are you going to modify every layer to pass along that value? No problemo. Just declare a dependency in the DAL constructor and the IoC will do the rest. Magic! BTW I wouldn't let Microsoft's CAB taint your view of IoC. That CAB is a behemoth. Some say that even after working with it for a year they still haven't grokked it.

                  Todd Smith

                  M B 2 Replies Last reply
                  0
                  • M Marc Clifton

                    I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                    Will work for food. Interacx

                    E Offline
                    E Offline
                    Erik Westermann
                    wrote on last edited by
                    #15

                    Dependency injection was like a solution looking for a problem. While loose coupling is nice, I wasn't convinced that such a high degree of loose coupling is necessary or provides any tangible benefits. I changed my mind when I saw something successfully use it: nServiceBus. nServiceBus' use of dependency injection results in an elegant and functional design that is surprisingly easy to use. I'm still not convinced that DI is ready for broad use since I still believe that it's a specialized approach to handle a specialized problem.

                    Erik Westermann - ArtOfBabel.com - Systems Integration Magazine
                    Contact Erik for consulting, development, or content creation at +1 416-809-1453 or via wWorkflow.net

                    1 Reply Last reply
                    0
                    • T Todd Smith

                      I use it in my web projects and find it really useful. You could create a service manager but what about managing the lifetime of objects? That's where IoC really shines imho. The real fun comes from using IoC along with XML configuration so you can change things on the fly. You also have to recode and recompile your service manager anytime a constructor adds or removes a dependency. Another good feature is property injection. If a class needs logging all we have to do is add public ILogger Log {get; set;} and Log gets set by the IoC after construction. No need to change a constructor or worse 50 constructors for a complex hierarchy of objects just to add logging. In a 4teir application web application -> services -> repository -> data access layer what happens when your DAL needs your HttpContext? Are you going to modify every layer to pass along that value? No problemo. Just declare a dependency in the DAL constructor and the IoC will do the rest. Magic! BTW I wouldn't let Microsoft's CAB taint your view of IoC. That CAB is a behemoth. Some say that even after working with it for a year they still haven't grokked it.

                      Todd Smith

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #16

                      Todd Smith wrote:

                      what happens when your DAL needs your HttpContext? Are you going to modify every layer to pass along that value?

                      Well no, but why not create a simple service container where you can add the HttpContext object, and give that container (in the constructor perhaps?) to classes that need it? Marc

                      Will work for food. Interacx

                      T 1 Reply Last reply
                      0
                      • M Marc Clifton

                        Todd Smith wrote:

                        what happens when your DAL needs your HttpContext? Are you going to modify every layer to pass along that value?

                        Well no, but why not create a simple service container where you can add the HttpContext object, and give that container (in the constructor perhaps?) to classes that need it? Marc

                        Will work for food. Interacx

                        T Offline
                        T Offline
                        Todd Smith
                        wrote on last edited by
                        #17

                        Marc Clifton wrote:

                        Well no, but why not create a simple service container where you can add the HttpContext object, and give that container (in the constructor perhaps?) to classes that need it?

                        Now your DAL has to know about your Service Manager which has to know about ALL of your other interfaces. You've created a coupling between everything in your system. That's like dipping your Jenga puzzle in a giant vat of glue. Or is your Service Manager type agnostic and you're doing a cast during every service request?

                        Todd Smith

                        1 Reply Last reply
                        0
                        • M Marc Clifton

                          I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                          Will work for food. Interacx

                          K Offline
                          K Offline
                          Kevin McFarlane
                          wrote on last edited by
                          #18

                          Not used it in anger but been reading around a bit. There are lighter alternatives to what you've tried though, e.g., Unity and Ninject. But I haven't done much more than "Hello World" with either so maybe they suck too?

                          Kevin

                          S B 2 Replies Last reply
                          0
                          • T Todd Smith

                            I use it in my web projects and find it really useful. You could create a service manager but what about managing the lifetime of objects? That's where IoC really shines imho. The real fun comes from using IoC along with XML configuration so you can change things on the fly. You also have to recode and recompile your service manager anytime a constructor adds or removes a dependency. Another good feature is property injection. If a class needs logging all we have to do is add public ILogger Log {get; set;} and Log gets set by the IoC after construction. No need to change a constructor or worse 50 constructors for a complex hierarchy of objects just to add logging. In a 4teir application web application -> services -> repository -> data access layer what happens when your DAL needs your HttpContext? Are you going to modify every layer to pass along that value? No problemo. Just declare a dependency in the DAL constructor and the IoC will do the rest. Magic! BTW I wouldn't let Microsoft's CAB taint your view of IoC. That CAB is a behemoth. Some say that even after working with it for a year they still haven't grokked it.

                            Todd Smith

                            B Offline
                            B Offline
                            Brady Kelly
                            wrote on last edited by
                            #19

                            Todd Smith wrote:

                            what happens when your DAL needs your HttpContext?

                            [Devil's Advocate Mode] Why would it? :~ [/Devil's Advocate Mode]

                            You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.

                            S 1 Reply Last reply
                            0
                            • B Brady Kelly

                              Todd Smith wrote:

                              what happens when your DAL needs your HttpContext?

                              [Devil's Advocate Mode] Why would it? :~ [/Devil's Advocate Mode]

                              You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.

                              S Offline
                              S Offline
                              Shog9 0
                              wrote on last edited by
                              #20

                              Heh, yeah, does seem like a bit of an odd dependency...  I assumed he just picked a class at random to use for an example.

                              T 1 Reply Last reply
                              0
                              • K Kevin McFarlane

                                Not used it in anger but been reading around a bit. There are lighter alternatives to what you've tried though, e.g., Unity and Ninject. But I haven't done much more than "Hello World" with either so maybe they suck too?

                                Kevin

                                S Offline
                                S Offline
                                Shog9 0
                                wrote on last edited by
                                #21

                                Kevin McFarlane wrote:

                                Not used it in anger

                                Ok, that's twice in the last two days i've seen this phrase used in relation to development tools... Are you seriously out there murdering people with text editors on a regular basis? :~

                                1 Reply Last reply
                                0
                                • K Kevin McFarlane

                                  Not used it in anger but been reading around a bit. There are lighter alternatives to what you've tried though, e.g., Unity and Ninject. But I haven't done much more than "Hello World" with either so maybe they suck too?

                                  Kevin

                                  B Offline
                                  B Offline
                                  Brady Kelly
                                  wrote on last edited by
                                  #22

                                  Kevin McFarlane wrote:

                                  But I haven't done much more than "Hello World"

                                  At least we know their natural language, idiom, and GUI services are OK.

                                  You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.

                                  1 Reply Last reply
                                  0
                                  • M Marc Clifton

                                    I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                                    Will work for food. Interacx

                                    E Offline
                                    E Offline
                                    emiaj
                                    wrote on last edited by
                                    #23

                                    You may want to give a try to StructureMap[^] As others had pointed out, one of the coolest things about IoC is the object's lifetime management. Good luck.

                                    Jaime Febres The worst blog in the world

                                    1 Reply Last reply
                                    0
                                    • M Marc Clifton

                                      I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                                      Will work for food. Interacx

                                      K Offline
                                      K Offline
                                      Kevin McFarlane
                                      wrote on last edited by
                                      #24

                                      Whether these things have merit or not I find that, as a contractor, it's worth playing around with them a bit if only for interview conversation topics. :-) We quite often get this kind of stuff thrown at us.

                                      Kevin

                                      1 Reply Last reply
                                      0
                                      • S Shog9 0

                                        Heh, yeah, does seem like a bit of an odd dependency...  I assumed he just picked a class at random to use for an example.

                                        T Offline
                                        T Offline
                                        Todd Smith
                                        wrote on last edited by
                                        #25

                                        Shog9 wrote:

                                        Heh, yeah, does seem like a bit of an odd dependency...  I assumed he just picked a class at random to use for an example.

                                        this

                                        Todd Smith

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          I've been playing around with Microsoft's CAB and a little bit with Spring.NET, and besides CAB having a major suckage issue[^] and Spring.NET seeming overly bloated for the majority of use cases, I'm wondering what people think about dependency injection (DI)? Personally, I don't really see the point of these frameworks. I don't think they improve upon the older way of doing things, where you pass in a service manager and you can then request whatever you want from the service manager. Thoughts? Marc

                                          Will work for food. Interacx

                                          M Offline
                                          M Offline
                                          martin_hughes
                                          wrote on last edited by
                                          #26

                                          I had a look at these things a while back. I wasn't wholly convinced. I suspect, like everything in IT, these Frameworks solve a certain class of problem and are quite good at it. I can imagine a situation where you have a well defined problem where different parties demand a different approach to solving that problem could be solved using dependency injection. What I am sure about is that zealots got hold of dependency injection and proclaimed it as the way. After that, forget logic, reason and anything remotely resembling independent thought... yeah, you just go ahead and f**k that sh1t because you've got the way. And the way is right and proper and must be used for everything.

                                          print "http://www.codeproject.com".toURL().text Ain't that Groovy?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups