Dependency Injection in Silverlight - Community Credit Forums
in

    Community Credit Forums

Dependency Injection in Silverlight

Last post Tue, Nov 4 2008 5:02 PM by faisal. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • Sat, Nov 1 2008 8:32 PM

    • faisal
    • Top 75 Contributor
    • Joined on Fri, Sep 19 2008
    • Posts 13

    Dependency Injection in Silverlight

    Can anyone please tell me what's the adavantage of implementing Dependency Injection in Silverlight? I'm not clear with this concept. Someone please clarify.
    Filed under:
  • Sun, Nov 2 2008 7:32 AM In reply to

    • CraigNicholson
    • Top 50 Contributor
    • Joined on Fri, Apr 20 2007
    • Johannesburg, Gauteng, South Africa
    • Posts 28
    • Moderator
      MVP

    Re: Dependency Injection in Silverlight

    Firstly I'd recommend reading up on DI and how it relates to Inversion of Control (IoC) over here. Basically you've most probably been using it for years and never knew the terminology. Its when some module or component of code doesn't take a reference to a resource but the resource is provided to it at runtime.

    Other than the obvious design decoupling advantages, one of the most popular uses of it are in mocking - that is faking a resource - and its generally used in testing code.

    So I reckon the potential for use in Silverlight is great as it allows for decoupled design.

  • Mon, Nov 3 2008 12:55 AM In reply to

    Re: Dependency Injection in Silverlight

    faisal:
    what's the adavantage of implementing Dependency Injection in Silverlight

     They are pretty much the same benefits of implementing DI in any environment.  Wink

    For the benefits of DI to really sink in I suggesting reading up on DI in general (the Wikipedia link is pretty good for that) and then head over to Jonas' blog where he does a great write up on Dependency Injection in Silverlight with Ninject (http://jonas.follesoe.no/YouCardRevisitedImplementingDependencyInjectionInSilverlight.aspx, I blogged about his article here: http://developingux.com/2008/10/07/dependency-injection-for-silverlight-with-ninject/)

    Benefits? 

    1. Testability - by having your dependencies automatically injected in to your objects it's much easier to create and load up mock objects to "shim" your services layer for example.

    2. Configurable - as mentioned above, not only can you configure out shimmed objects for real ones, but you can also quickly and easily make configuration or run time changes in a single place without breaking the rest of your application.So, for example, you could have an Interface defined for a shipping service (IShippingService) and then create:
    • ShippingMock : IShippingService - for testing in isolation
    • FedExService : IShippingService - for actually sending your items
    • UPSService : IShippingService - in case you're wondering what Brown can actually do for you.
    In addition to the traditional DI, if you implement a MVP pattern in your UI then you can combine that with DI to produce a very flexible code base for doing things like multi-targeting various form factors (like Silverlight Mobile for example)Once you start developing in a loosely coupled, dependency injection approach.. you'll find that it's hard to go back. It's a very nice, flexible approach to writing software. I'll be speaking on this very topic at VS Live Dallas in December (http://developingux.com/2008/10/29/vslive-dallas-reg-code/)The surprising thing about doing DI in Silverlight... isn't on the DI side, it's that you can actually leverage some of these frameworks and bring great architectural and application designs in to the browser with Silverlight 2!

     

    Caleb Jenkins
    blog: DevelopingUX | video: CommunityCast TV
    twitter: calebjenkins
    .NET Mentoring company: Proactio Mentors
  • Tue, Nov 4 2008 5:02 PM In reply to

    • faisal
    • Top 75 Contributor
    • Joined on Fri, Sep 19 2008
    • Posts 13

    Re: Dependency Injection in Silverlight

    Thanks to both Craig and Caleb for helping me out in getting some crucial information on Dependecy Injection. Thanks a lot guys. I'll get back to you if I find something hazy on this issue.
Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems