Book Image

Data Oriented Development with Angularjs

Book Image

Data Oriented Development with Angularjs

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Dependency injection


The dependency injection pattern, as the name suggests, is the process of injecting dependencies (or services) into another (client) object. It is also referred to as Inversion of Control (IoC). Without it, a client has to create instances of dependent objects itself, whereas with dependency injection, these objects are handed to the client by someone else (typically, an IoC container). This is commonly referred to as the Hollywood principle—"don't call us, we'll call you". The following is an example C# code to make things more clear:

public interface IShippingService {
  double CalculateShippingCost ();
}

public class ShippingService : IShippingService {
  double CalculateShippingCost () {
    // do some lengthy calculation here and
    // calculate the shipping cost
  }
}

public class LoggingShippingService : IShippingService {
  double CalculateShippingCost () {
    // do some lengthy calculation here and
    // calculate the shipping cost
    Console.WriteLine...