liveBook · Manning

Dependency injection

Also called DI, injecting dependencies

Dependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.

How 28 Manning books explain it

ASP.NET Core in Action, 3e

Dependency injection is a design pattern in which an object receives its dependencies from an external provider rather than creating them itself.

How it is used
Uses DI to compose ASP.NET Core framework features and application services while keeping consumers loosely coupled.
How deep it goes
Explains dependency graphs, service registration and resolution, lifetime choices, and common pitfalls; also introduces filter-specific injection.
Examples
Illustrates injection with an email registration endpoint, a link generator, a repository and data context, and Razor Page and filter services.
What you can do after
Apply it via the ASP.NET Core DI container by registering services, injecting dependencies, and selecting lifetimes.

Read how ASP.NET Core in Action, 3e explains dependency injection →

Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

Dependency injection is a design pattern in which high-level modules obtain low-level dependencies through an abstraction rather than constructing or directly binding to them.

How it is used
Deploys infrastructure dependencies and refactors IaC so high-level resources can evolve independently of low-level resources.
How deep it goes
Explains principles, provider APIs, Python implementations, pattern selection, and refactoring steps through infrastructure examples.
Examples
Uses GCP servers, networks, subnets, storage buckets, access controls, firewalls, and monolithic IaC refactoring.
What you can do after
Apply it via Apache Libcloud or provider APIs to isolate infrastructure changes and organize dependent resource creation.

Read how Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform explains dependency injection →

.NET MAUI in Action

Dependency injection is a technique in which an object receives its required dependencies from an external provider rather than constructing them itself.

How it is used
Organizes pages, ViewModels, services, authentication, and HTTP clients through the .NET MAUI host container.
How deep it goes
Explains registration scopes and constructor injection through pages, services, ViewModels, and named HTTP clients.
Examples
Uses AuthService and LoginPage constructors, injected page ViewModels, and a named authenticated HttpClient.
What you can do after
Apply it via the .NET MAUI ServiceCollection to register and constructor-inject app dependencies.

Read how .NET MAUI in Action explains dependency injection →

Modern Angular

Dependency injection is a software design technique in which a framework supplies an object's required dependencies rather than the object constructing them itself.

How it is used
Supplies services and configuration to Angular building blocks without manual construction.
How deep it goes
Explains provider registration, token lookup, hierarchy modifiers, and a primitive injector implementation.
Examples
Demonstrates a minimal Injector and a configurable TruncateDirective for employee-table text.
What you can do after
Apply it via Angular providers, InjectionToken, and inject() to share services and configure reusable features.

Read how Modern Angular explains dependency injection →

Test Driven: Practical TDD and Acceptance TDD for Java Developers

Dependency injection is a software design pattern in which an object receives its dependencies from an external source rather than obtaining them itself.

How it is used
Introduces dependency injection as a way to make collaborators replaceable in tests and configure Spring controllers for deployment.
How deep it goes
Works through setter injection and test setup, contrasting it with an overridable getter and showing Spring configuration’s role.
Examples
Uses an order processor with a fake pricing service and a login controller with an authentication service.
What you can do after
Apply it via setters and Spring configuration to supply test doubles or deployment implementations.

Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers explains dependency injection →

Shipping Go: Develop, deliver, discuss, design, and go again

Dependency injection is a software design technique in which a component receives the services or objects it depends on from outside rather than constructing them itself.

How it is used
Decouples a Go HTTP handler from its translation service so implementations can change and handler tests can control service results.
How deep it goes
Works through interface definition, constructor injection, manual application wiring, and test stubs; leaves automated wiring to named alternatives.
Examples
Uses a translation handler, a static translation service, application route setup, and a stub returning fixed test values.
What you can do after
Build it from scratch by hand-wiring a Go service into a handler and injecting a stub for isolated handler tests.

Read how Shipping Go: Develop, deliver, discuss, design, and go again explains dependency injection →

Functional Design and Architecture: Examples in Haskell

Dependency injection is a technique for supplying a component's external functionality through an abstraction rather than constructing or selecting its concrete implementation internally.

How it is used
Decouples business logic from external subsystem implementations through injected interfaces.
How deep it goes
Explains interface selection and injection through service handles, then compares functional approaches and their trade-offs.
Examples
Illustrates injected greetings handles, configurable meteor reporting, and a mocked database outage.
What you can do after
Apply dependency injection using service handles and evaluate alternative functional interfaces for coupling and testability.

Read how Functional Design and Architecture: Examples in Haskell explains dependency injection →

Kafka Streams in Action, Second Edition

Dependency injection is a design technique in which an object's required dependencies are supplied by external configuration or a framework rather than created by the object itself.

How it is used
Wires Spring Kafka and Kafka Streams components so processors receive infrastructure and configuration without constructing them.
How deep it goes
Defines IoC and injection styles, then demonstrates constructor and property wiring in Java components; detailed container internals are not developed.
Examples
Demonstrates a PaymentProcessor with NetworkClient and loan processors receiving KafkaTemplate, StreamsBuilder, and KafkaStreamsConfiguration.
What you can do after
Apply it via Spring annotations to wire collaborators, configuration properties, and Kafka infrastructure into application components.

Read how Kafka Streams in Action, Second Edition explains dependency injection →

Pro Angular 16

Dependency injection is a technique in which a framework supplies an object's required dependencies rather than the object constructing them directly.

How it is used
Supplies shared services to components without constructing them directly or passing them through parent inputs.
How deep it goes
Works through decorators, providers, constructor parameters, and a service dependency chain; does not detail injector internals.
Examples
Uses a shared discount editor and display, a cart, and a repository that depends on a data source.
What you can do after
Build it from scratch: decorate and register Angular services, inject them through constructors, and replace direct construction or parent-mediated sharing.

Read how Pro Angular 16 explains dependency injection →

Pro ASP.NET Core 7, Tenth Edition

Dependency injection is a software design technique in which a component receives its dependencies from external configuration or composition rather than creating them itself.

How it is used
Supplies registered services to ASP.NET Core request handlers and components without making consumers select implementation classes.
How deep it goes
Works through registration, constructor and handler injection, service-provider access, activation utilities, and lifetime choices.
Examples
Uses a repository-backed product controller, a mock repository test, and response formatting in middleware and endpoints.
What you can do after
Apply it via ASP.NET Core service registration and injection to replace implementations and isolate consumers for unit tests.

Read how Pro ASP.NET Core 7, Tenth Edition explains dependency injection →

The Art of Unit Testing 3e

A technique in which a component receives a value or behavior from outside rather than creating it internally.

How it is used
Makes time and logging dependencies replaceable so tests can control inputs or observe calls.
How deep it goes
Works through value, function, factory, module, and constructor injection; defers container configuration details.
Examples
Uses a weekend-sensitive password verifier, fake time providers, a replaceable module import, and a mock logger.
What you can do after
Build it from scratch with parameters or factories to supply controlled dependencies and make tests repeatable.

Read how The Art of Unit Testing 3e explains dependency injection →

Learn Go with Pocket-Sized Projects

Dependency injection is a technique in which an object or component receives its required dependencies from outside rather than constructing them internally.

How it is used
Decouples application logic from external services and supplies replaceable implementations for production, development, and tests.
How deep it goes
Defines the pattern and demonstrates interface, function, local-function, and repository forms, stopping short of broader framework machinery.
Examples
Uses exchange-rate providers, configurable fetcher functions, and a habits repository injected into a gRPC server and domain function.
What you can do after
Apply it via Go interfaces or function parameters to replace external services, constrain dependencies, and mock behavior during tests.

Read how Learn Go with Pocket-Sized Projects explains dependency injection →

Spring Start Here, Second Edition

Dependency injection is a pattern in which an object's dependencies are supplied by an external component rather than constructed by the object itself.

How it is used
Connects Spring-managed objects so they can collaborate without manually retrieving each dependency from the context.
How deep it goes
Explains configuration-method, field, constructor, and setter injection, including ambiguity resolution and circular dependencies.
Examples
Uses Person and Parrot beans to demonstrate method-parameter injection and selection among multiple beans.
What you can do after
Apply it via Spring to wire beans, select among matching candidates, and inject interface implementations.

Read how Spring Start Here, Second Edition explains dependency injection →

Build Python Web Apps with Streamlit

Dependency injection is a software design pattern in which an object receives the components it depends on from outside rather than constructing them internally.

How it is used
Separates application setup from graph logic while supporting automated testing.
How deep it goes
Defines the pattern and demonstrates constructor injection, but does not develop testing techniques beyond stating the benefit.
Examples
Uses Bot, SupportAgentGraph, an LLM, and a VectorStore as the construction-and-injection example.
What you can do after
Build applications that pass configured services into focused components instead of constructing dependencies inside them.

Read how Build Python Web Apps with Streamlit explains dependency injection →

Functional Programming in C#, Second Edition

A software design pattern in which a component receives the dependencies it needs from an external source rather than creating them itself.

How it is used
Makes code dependent on I/O testable by supplying predictable dependencies in place of real operations.
How deep it goes
Walks through interface injection and contrasts it with injecting a value or function, including registration and lifetime choices.
Examples
Uses a transfer-date validator, a fake clock, and fixed-date tests to compare injection approaches.
What you can do after
Evaluate dependency injection options for making a clock-dependent validator predictable under test.

Read how Functional Programming in C#, Second Edition explains dependency injection →

gRPC Microservices in Go

Dependency injection is a design technique in which a component receives its required collaborators from outside rather than constructing them internally.

How it is used
Wires database, payment, and gRPC adapters into an Order service without making its application core construct those adapters.
How deep it goes
Shows constructor-level injection and startup wiring in Go, including an expanded payment dependency.
Examples
Uses an Order service whose startup injects database and payment adapters into its application and that application into a gRPC adapter.
What you can do after
Build it from scratch by defining port-based dependencies and constructing their adapters at service startup.

Read how gRPC Microservices in Go explains dependency injection →

Building Web APIs with ASP.NET Core

Dependency injection is a software design pattern in which a component receives its required dependencies from an external provider rather than constructing them itself.

How it is used
Deploys dependency injection to provide ASP.NET Core services and database contexts to controllers without manual construction.
How deep it goes
Explains implementation, registration, and constructor injection, then demonstrates database querying without descending into container internals.
Examples
Uses Program.cs registration and a BoardGamesController receiving ApplicationDbContext to replace dummy data with database results.
What you can do after
Apply it via ASP.NET Core constructor injection to access ApplicationDbContext from controller action methods.

Read how Building Web APIs with ASP.NET Core explains dependency injection →

.NET in Action, Second Edition

Dependency injection is a pattern in which an object receives its dependencies from an external composition mechanism rather than creating them itself.

How it is used
Deploys inversion of control in ASP.NET Core controllers so the application supplies data-access dependencies at request time.
How deep it goes
Explains dependencies, constructor provision, lifetime control, service registration, and test substitution.
Examples
Uses CatalogController receiving CatalogContext, AddDbContext registration, and fake or mock replacements during testing.
What you can do after
Apply it via ASP.NET Core service registration and constructor injection, then substitute fakes or mocks during testing.

Read how .NET in Action, Second Edition explains dependency injection →

Simple Object-Oriented Design: Create clean, maintainable applications

A dependency injection framework is a software framework that constructs objects and supplies their declared dependencies according to configuration or conventions.

How it is used
Uses constructor-supplied collaborators to make components modular, flexible, and easier to test in isolation.
How deep it goes
Explains constructor injection, dependency graphs, testing benefits, performance objections, and framework-versus-factory tradeoffs without detailing framework configuration.
Examples
Uses ImportEmployeesService, an SDKBot wrapping ChatBotV1, and the MessageSender dependency graph.
What you can do after
Apply it via constructors, frameworks, or factories to substitute implementations and isolate collaborators in tests.

Read how Simple Object-Oriented Design: Create clean, maintainable applications explains dependency injection →

Rust Servers, Services, and Apps

Dependency injection is a technique in which a component receives the resources or services it needs from an external provider.

How it is used
Coordinates shared application state and database services across Actix Web handlers.
How deep it goes
Builds injection incrementally through state structs, web::Data registration, handler parameters, and a compiling server; defers completed database logic.
Examples
Uses a visit-count health check and a tutor service that injects a PostgreSQL pool into course and registration handlers.
What you can do after
Build it from scratch by registering shared Actix state and retrieving it from handler parameters.

Read how Rust Servers, Services, and Apps explains dependency injection →

Crack Any Codebase with AI

Dependency injection is a technique in which an object's required collaborators are supplied from outside rather than created or imported directly.

How it is used
Uses dependency injection to explain how large VS Code services locate one another and support swappable extension implementations.
How deep it goes
Explains the architectural purpose through a production-scale example but stops short of implementation mechanics or configuration steps.
Examples
Uses VS Code themes, languages, files, and extension-provided implementations as concrete service examples.
What you can do after
Evaluate how a large codebase enables service collaboration and extension-level implementation replacement.

Read how Crack Any Codebase with AI explains dependency injection →

Grokking Software Architecture

Injection is the process of providing a dependency to the object that needs it.

How it is used
Uses injected dependencies to loosen coupling and make components easier to test.
How deep it goes
Defines injection and works through constructor-based database and logger examples, including a fake-dependency test.
Examples
Uses report-generator tests with real and fake databases, plus an OrderService that receives a logger.
What you can do after
Apply it by passing a fake database or logger into a component instead of hard-coding that dependency.

Read how Grokking Software Architecture explains dependency injection →

Microservices Patterns, Second Edition

Dependency injection is a technique in which an object's or component's dependencies are supplied from outside rather than constructed internally.

How it is used
Supports automated testing by making troublesome dependencies replaceable with test doubles.
How deep it goes
Explains test-double substitution and its testing benefits without detailing implementation mechanics.
Examples
Demonstrates simulating an external service and mocking a DAO to avoid database access in tests.
What you can do after
Apply it to substitute a troublesome service or DAO with a test double and enable faster in-memory unit tests.

Read how Microservices Patterns, Second Edition explains dependency injection →

Go by Example

Dependency injection is a software design technique in which required dependencies are supplied to a component from outside rather than created internally.

How it is used
Improves CLI and middleware testability by replacing global dependencies with explicit inputs.
How deep it goes
Explains refactoring steps, injected structs, interfaces, fakes, and explicit logger configuration, stopping short of framework-based techniques.
Examples
Uses a CLI env struct with in-memory buffers and middleware configured with an explicitly injected logger.
What you can do after
Build testable CLI and middleware components by passing real or fake dependencies through explicit parameters.

Read how Go by Example explains dependency injection →

Spring in Action, Sixth Edition

A framework that supplies an object's dependencies from outside the object rather than requiring the object to construct them.

How it is used
Uses a Spring application context to create, manage, and wire application components into a working application.
How deep it goes
Explains container-managed beans, constructor arguments, and property accessors through a simple service relationship.
Examples
Uses inventory and product services, XML bean definitions, Java @Configuration, and @Bean methods.
What you can do after
Apply it via Spring by defining service beans and wiring a product service to an inventory service.

Read how Spring in Action, Sixth Edition explains dependency injection →

Go in Action, Second Edition

Dependency injection is a design technique in which a component receives its required collaborators from outside rather than constructing them internally.

How it is used
Connects HTTP handlers to domain capabilities while keeping dependency construction at the application boundary.
How deep it goes
Demonstrates constructor injection with a narrowed interface and concrete storage implementation.
Examples
Uses Go handlers, ArticleReader, BoltStore, route registration, and an API module structure.
What you can do after
Build it from scratch by injecting a concrete storage implementation into a handler that requires only a read interface.

Read how Go in Action, Second Edition explains dependency injection →

100 Go Mistakes and How to Avoid Them

Dependency injection is a technique in which a component receives required dependencies from its caller rather than constructing or retrieving them internally.

How it is used
Uses injected dependencies to make time-dependent tests deterministic and isolated.
How deep it goes
Explains struct fields, constructors, fake functions, interfaces, globals, and caller-provided values, but stops short of broader dependency graphs.
Examples
Uses a Cache, event timestamps, time.Now, fixed timestamps, fake clock functions, and cutoff-time arguments.
What you can do after
Diagnose flaky time-dependent tests and choose struct injection or caller-provided time to make outcomes reproducible.

Read how 100 Go Mistakes and How to Avoid Them explains dependency injection →

Clean Applications with Hexagonal Architecture

Dependency injection is a design technique in which an object's dependencies are supplied by external configuration or infrastructure.

How it is used
Connects ports to adapters at runtime so separately testable hexagonal components can operate as a system.
How deep it goes
Explains assembly-module visibility, bean discovery, interface matching, and injection while keeping framework wiring outside the core.
Examples
Uses Spring assembly to connect ArticleRepository to its adapter and injects ArticleIdGenerator into ArticleFactory.
What you can do after
Operate Spring Boot assembly to resolve interfaces to implementations and inject external services into factories.

Read how Clean Applications with Hexagonal Architecture explains dependency injection →

Also covered in

What to know first

Related concepts

Questions about dependency injection

What is dependency injection?

Dependency injection is a software design technique in which a component receives its dependencies from outside rather than creating or locating them internally.

Which Manning books explain dependency injection?

ASP.NET Core in Action, 3e, Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform, .NET MAUI in Action, Modern Angular, Test Driven: Practical TDD and Acceptance TDD for Java Developers, Shipping Go: Develop, deliver, discuss, design, and go again, Functional Design and Architecture: Examples in Haskell, Kafka Streams in Action, Second Edition and 20 more.

What should I know before learning dependency injection?

Manning books that teach dependency injection usually introduce dependency, contract, software testing and unit test first.

What kinds of dependency injection are there?

Kinds of dependency injection include constructor injection and setter injection.

What is dependency injection also called?

Dependency injection is also called DI or injecting dependencies.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.