Thursday, January 13, 2011

Inversion of Control

  • It breaks dependencies between classes and promote loose coupling.
  • IoC is about programming to interface, if A uses B, then you can create an interface I that B implements and then let A uses an instance of I.
  • Dependency Injection & Service Locator are two ways of implementing IoC.
  • Dependency Injection
    • Constructor injection: Constructor Injection is the DI technique of passing an object's dependencies to its constructor.
    • Property injection
  • IoC is vital for doing Test Driven Development. To be able to unit test your ASP.NET application, we will need to loose couple the business logic layer and data access layer, a mock object can be used. A mock object simulates the responses of an actual object, acting as if it's using a real resource. They're great for mocking access to a database, mocking calls to IO, mocking calls to a web service, etc.
References:
blog comments powered by Disqus