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.
  • 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
                                • 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
                                  moon_stick
                                  wrote on last edited by
                                  #27

                                  I read an article this week about dependency injection with relation to testing which I thought made some good points; rather than reiterate what was printed, the article's here[^]!

                                  It definitely isn't definatley

                                  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

                                    J Offline
                                    J Offline
                                    Jeremy Likness
                                    wrote on last edited by
                                    #28

                                    One problem I see with DI is that a lot of people confuse the framework (Unity, Spring, Windsor, etc) with the concept and pattern. When you are talking about containers and having massive XML configuration files or bootstrappers, etc, you are getting into frameworks and adding a ton of overhead. Sometimes it may be justified. However, DI in and of itself is simple.

                                    public class DataAccessObject
                                    {
                                    private ILogger _logger;

                                      public DataAccessObject()
                                      {
                                         \_logger = LoggerFactory.GetLogger();
                                      }
                                    
                                      public DataAccessObject(ILogger logger) 
                                      {
                                          \_logger = logger;
                                      }
                                    
                                      public void WriteSomething(string something)
                                      {
                                           ...
                                           \_logger.log(something);
                                      }
                                    

                                    }

                                    This is easy enough to do and no framework required. The "factory" might just return a concrete instance, but by using the factory pattern you can at least change your logger in one place, for example. Adding a framework allows you to put it into a container, and then you can request the object from the container and have the logger injected by the container, etc, but it doesn't always require that level fo complexity. I think the pattern itself lends to solving many problems if you follow Don't Repeat Yourself and Single Responsibility, etc, etc but again, DI as a concept I think is great, whereas the frameworks around it are going to require looking at the flexibility vs. performance and overhead etc etc. It's like choosing a data access strategy between the native SQL client vs. Enterprise Library vs. NHibernate vs. Entity framework, etc ... data access as a pattern obviously is important, HOW you persist your entities depends on more than just saying, "Is saving objects to a database to persist them a good thing?" Jeremy

                                    1 Reply 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

                                      Z Offline
                                      Z Offline
                                      zkosior
                                      wrote on last edited by
                                      #29

                                      Passing interface is a Dependency Injection (property, constructor etc.). If you need to pass small interface than consider Role Interfaces. IoC containers can themselves be small. - bynio

                                      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

                                        J Offline
                                        J Offline
                                        JasonCordes
                                        wrote on last edited by
                                        #30

                                        It can be very useful and powerful. And it can allow for configuration of objects that is truly transcendent. Unfortunately, it can be a maintenance nightmare. Trying to track down where, how and why an object is used can be at best difficult and at worst nearly impossible if everything is Injected. Interfaces are the true evil here. While interfaces can be used for good, in my opinion DI uses them for evil. Pure rotten evil. If you have a system of sufficient size (say over 100KLOC), try to avoid DI, it will only cause confusion and delay in the development and more importantly maintenance of your software. I think DI is excellent for prototypes and games, though.

                                        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

                                          J Offline
                                          J Offline
                                          Jordan Marr
                                          wrote on last edited by
                                          #31

                                          I'm using Unity container (not the whole CAB) on my current web app and am really enjoying it. My service classes all have a base class that has ICache, IMessaging, ISessionDescriptor, IDataPortal, IExceptionHandler, etc. These are passed into the constructor and resolved by Unity. An interesting one is IMessaging. I have a user control that lives in a master page that is responsible for displaying messsages, validation errors, etc, that implements IMessaging. The user control registers itself via RegisterInstance with Unity. Then when I resolve a service class, the correct instance of IMessaging is automatically resolved, and my service layer can indirectly handle displaying messages & validation errors. Actually, the app uses two different master pages that reference the same messaging user control, but the user control registers itself with Unity, so that is transparent to my service classes, which can rely on the fact that IMessaging will always be available for their use. I also like being about to "resolve" my service classes from the UI layer without without having to construct all this stuff manually. Another plus when resolving a service class is that if any of its pluggable dependencies have their own pluggle dependencies, they will be automatically resolved too. Jordan

                                          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