Chapter 1. A Dependency Injection tasting menu
Listing 1.2. Extending the Hello DI application with a security feature
Chapter 2. A comprehensive example
Listing 2.1. Mary’s ProductService class
Listing 2.2. Index method on the default controller class
Listing 2.3. Index View markup
Listing 2.4. Index View markup
Listing 2.5. HomeController with CONSTRUCTOR INJECTION
Listing 2.6. ProductService class
Listing 2.7. Implementing ProductRepository using LINQ to Entities
Chapter 3. DI Containers
Listing 3.1. Configuring Unity with XML
Chapter 4. DI patterns
Listing 4.1. CONSTRUCTOR INJECTION
Listing 4.2. Injecting a CurrencyProvider into the BasketController
Listing 4.3. PROPERTY INJECTION
Listing 4.4. Exposing a CurrencyProfileService property
Listing 4.5. Checking a method parameter for null before using it
Listing 4.6. A sample add-in client
Listing 4.8. Converting Money to another currency
Listing 4.9. Converting a Basket’s currency
Listing 4.10. SQL Server–backed Currency implementation
Listing 4.12. TimeProvider AMBIENT CONTEXT
Listing 4.13. Default time provider
Listing 4.14. Caching the exchange rate
Listing 4.15. Unit testing that a currency is correctly cached and expired
Chapter 5. DI anti-patterns
Listing 5.1. newing up a ProductRepository
Listing 5.2. ProductService with BASTARD INJECTION
Listing 5.3. Implicitly constraining the ProductRepository constructor
Chapter 6. DI refactorings
Listing 6.1. Using an IRouteAlgorithmFactory
Listing 6.2. Creating a child window
Listing 6.3. Deferred initialization of DEPENDENCIES
Listing 6.4. Enforcing loose coupling with a unit test
Listing 6.5. Enforcing loose coupling with an integration test
Chapter 7. Object Composition
Listing 7.1. Console application COMPOSITION ROOT
Listing 7.2. Custom CurrencyContainer
Listing 7.3. Creating Controllers
Listing 7.4. Custom ServiceHostFactory
Listing 7.5. Custom ServiceHost
Listing 7.6. CommerceInstanceProvider class declaration and constructor
Listing 7.7. IInstanceProvider implementation
Listing 7.8. Core implementation of IContractBehavior
Listing 7.9. Resolving ProductManagementService
Listing 7.10. Composing the main window
Listing 7.11. Implementing a WPF COMPOSITION ROOT
Listing 7.12. Composing a Presenter as data source
Listing 7.13. Resolving CampaignPresenter
Listing 7.14. Deleting baskets more than a month old
Chapter 8. Object Lifetime
Listing 8.1. Composing with multiple instances of the same DEPENDENCY
Listing 8.2. Managing lifetime with a container
Listing 8.3. Configuring Autofac with TRANSIENT DEPENDENCIES
Listing 8.4. Associating disposable DEPENDENCIES with a resolved root
Listing 8.5. Releasing disposable DEPENDENCIES
Listing 8.6. Managing SINGLETONS
Listing 8.7. Resolving TRANSIENT DiscountRepositorys
Listing 8.8. Resolving a single repository per graph
Listing 8.9. Composing HomeController
Listing 8.10. Resolving a web request context-scoped DEPENDENCY
Listing 8.11. Releasing disposable WEB REQUEST CONTEXT–scoped DEPENDENCIES
Listing 8.12. Laying out a foundation for a pooling container
Chapter 9. Interception
Listing 9.1. Declaring an AuditingProductRepository
Listing 9.2. Implementing AuditingProductRepository
Listing 9.3. Composing a Decorator
Listing 9.4. Decorating with a Circuit Breaker
Listing 9.5. Handling exceptions
Listing 9.6. Explicitly checking authorization
Listing 9.7. Violating the DRY principle
Listing 9.8. Implementing the exception handling Interceptor
Chapter 10. Castle Windsor
Listing 10.1. Implementing a Windsor Installer
Listing 10.2. Defining a custom lifestyle
Listing 10.3. Implementing the Resolve method
Listing 10.4. Implementing an ILease
Listing 10.5. Naming components
Listing 10.6. Registering named courses
Listing 10.7. Overriding AUTO-WIRING
Listing 10.8. Explicitly defining an array of services
Listing 10.9. Explicitly configuring a Decorator
Listing 10.10. Supplying a primitive constructor argument value
Chapter 11. StructureMap
Listing 11.1. Implementing a custom convention
Listing 11.2. Implementing a Registry
Listing 11.3. Implementing a lifestyle-declaring convention
Listing 11.4. Implementing ILifecycle
Listing 11.5. Constructing LeasedObjectCache
Listing 11.6. Implementing Get and Set
Listing 11.7. Using different cache lifestyles for each Instance
Listing 11.8. Naming Instances
Listing 11.9. Configuring named courses
Listing 11.10. Overriding AUTO-WIRING
Listing 11.11. Using Instance references to override AUTO-WIRING
Listing 11.12. Using Instance references to inject a sequence
Chapter 12. Spring.NET
Listing 12.1. Wiring a list of dependencies
Listing 12.2. Translating requests for a sequence into requests for arrays
Listing 12.3. Injecting named objects into a sequence
Listing 12.4. Implementing an exception handling IMethodInterceptor
Listing 12.5. Implementing a Circuit Breaker IMethodInterceptor
Chapter 13. Autofac
Listing 13.1. Implementing an Autofac Module
Listing 13.2. Registering named courses
Listing 13.3. Overriding AUTO-WIRING
Listing 13.4. Overriding AUTO-WIRING with a convention
Chapter 14. Unity
Listing 14.1. Registering all IIngredients in an assembly
Listing 14.2. Implementing a Container Extension
Listing 14.3. Implementing a custom LifetimeManager
Listing 14.4. Disposing a LifetimeManager
Listing 14.5. Implementing a custom LifetimeStrategy
Listing 14.6. Extending Unity with CacheLifetimeStrategy
Listing 14.7. Implementing a releasing strategy
Listing 14.8. Naming registrations
Listing 14.9. Registering named courses
Listing 14.10. Overriding AUTO-WIRING
Listing 14.11. Injecting named components into a sequence
Listing 14.12. Decorating with a named component
Listing 14.13. Implementing an exception handling IInterceptionBehavior
Listing 14.14. Implementing a Circuit Breaker IInterceptionBehavior
Chapter 15. MEF
Listing 15.1. Exporting OliveOil via an adapter
Listing 15.2. Adapting a class with DEPENDENCIES
Listing 15.3. Implementing a custom catalog
Listing 15.4. Defining named exports
3.17.174.0