Wednesday, May 14, 2008

Taming Software Dependencies with DI and IoC

with James Kovacs

Concepts

  • Dependency Inversion (IoC)
    • Higher levels should not rely on lower levels
    • Abstraction
    • Both should depend on something else (contract)
  • Dependency Injection
    • supply your dependencies to your objects
      • Through the constructor or through setters
      • Mandatory in constructor and optional in setters
  • Problem:The presenter needs too know about the dependencies below
    • Solution 1
      • Write a default constructor that sets up the dependencies
    • Solution 2
      • Use and IoC Container
        • At the core a dictionary
        • Static gateway from JP is a basic example of this
      • Windsor
        • Does dependency resolution
          • Autowiring
        • Lifetime management
        • Multiconfig options
          • Run-time config
        • Plug-ins

Dependencies

  • If you pull out a class, how many other classes do you have to copy over too

Notes

  • Don't fear the code
  • Wizards constrain you
    • MVC wizards is a good example
  • .Net Pet Has a lot of coupling
  • In DDD you use the language of the business
    • Use Submit instead of Save for example
  • Decorator Pattern
    • Add functionality on top of and existing class
      • such as logging
    • Could we have done WSDBLink as a decorator?
  • Use "`" in XML for Generics

Tools

  • MS Unity DI tool
  • Windsor - OSS DI Software
  • StructureMap
  • Spring.Net
  • Bindsor
    • Boo code to set up Windsor

No comments: