Dependency Injection in C# and .NET with the Autofac Library
4.3 (768 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5,929 students enrolled

Dependency Injection in C# and .NET with the Autofac Library

An in-depth course on Dependency Injection and Inversion of Control
Bestseller
4.3 (768 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5,929 students enrolled
Created by Dmitri Nesteruk
Last updated 1/2020
English
English [Auto], Indonesian [Auto], 3 more
  • Polish [Auto]
  • Romanian [Auto]
  • Thai [Auto]
Current price: $34.99 Original price: $49.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 5.5 hours on-demand video
  • 1 article
  • 32 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Understand and leverage the benefits of dependency injection
  • Plan and configure dependency injection containers
  • Leverage dependency injection scopes, modules and other advanced capabilities
  • Integrate dependency injection with popular frameworks (e.g., ASP.NET
Course content
Expand all 57 lectures 05:21:04
+ Introduction
1 lecture 02:39

At look at what's included in this course.

Preview 02:39
+ Dependency Injection and Inversion of Control
3 lectures 21:51

Let's get familiar with the two key terms: DI and IoC.

Dependency Injection and Inversion of Control
16:15

A discussion of the different DI frameworks that exist. There are many!

An Overview of DI Frameworks
04:21

How to install and start using Autofac. Very easy, actually, since Autofac is available on NuGet.

Getting Started with Autofac
01:15
+ Registration Concepts
9 lectures 40:00

Time to get started learning Autofac. Here's what we've got in store for this section.

Overview
03:34

The key scenario which we're going to be using throughout most of the lessons in this course. No dependency injection yet, that will come in the next lesson!

Scenario (Without DI)
06:49

Time to use Autofac! We register some components and watch the container weave its magic.

Registering Types (Reflection Components)
07:16

What happens if you register multiple components for the ILog service?

Default Registrations
04:23

If your class has multiple constructors, how does the container know which one to call?

Preview 02:50

Instead of registering a type to be created on demand, you can define an existing instance to be used whenever a component of a particular type is required.

Registering Instances (Instance Components)
02:42

You can make component registrations using lambda expressions instead of type parameters. This affords additional flexibility.

Preview 04:17

What happens when you try to register (and subsequently resolve) generic types?

Open Generic Components
03:08

A summary of all the things we've learned in this section of the course.

Summary
05:01

Check your comprehension of this section.

Registration Concepts Quiz
5 questions
+ Advanced Registration Concepts
8 lectures 52:03

An overview of the things we're going to encounter in this section of the course.

Overview
02:17

We look at how parameters can be explicitly passed into the constructor of the instantiated component at the registration stage. We also look at an example of a lambda expression component that delays parameter value passing until the resolution stage.

Passing Parameters to Register()
12:25

Parameter passing is a little clumsy, so delegate factories provide an alternative approach.

Delegate Factories
06:55

One common problem when working with DI is how to resolve a type at an arbitrary point in your code. Well, delegate methods are very useful for this.

Objects on Demand
05:49

The constructor is the default way of adding dependencies, but you can also inject them into properties or specify methods that explicitly assign the dependencies.

Property and Method Injection
08:58

Registering components one by one is tedious. How about registering all components from an assembly?

Scanning for Types
04:22

We introduce the concept of a module as a self-contained registration unit.

Scanning for Modules
03:20

A summary of all the things we've met in this section of the course.

Summary
07:57

Test your comprehension by answering these questions.

Advanced Registration Concepts Quiz
4 questions
+ Implicit Relationship Types
10 lectures 48:51

An overview of the things we are going to encounter in this section of the course.

Overview
03:03

Configuring components that you don't need to be constructed straight away.

Delayed Instantiation
05:47

What if a component wants to take responsibility for another component's lifetime?

Controlled Instantiation
04:15

Auto-generated factories and why you might need them.

Dynamic Instantiation
05:11

Now that we're using Func<>, what about passing in parameters?

Parameterized Instantiation
03:40

What happens when you inject an IEnumerable or similar collection interface.

Preview 05:52

Attaching metadata to components and reading them inside these components.

Metadata Interrogation
09:05

Accessing a specific service by key. Kind of like Enumeration injection, but with an IDictionary.

Keyed Service Lookup
05:33

A cautionary note about getting too dependent on your DI container.

Container Independence
03:20

A summary of the things we've learned in this section of the course.

Summary
03:05

Test your comprehension by answering these questions.

Implicit Relationships Types Quiz
7 questions
+ Controlling Scope and Lifetime
7 lectures 46:19

A taste of things to come.

Overview
02:31

Scopes are used to control the lifetime of created components.

Instance Scope
12:20

What happens when long-lived components accidentally (or deliberately) hold onto short-lived components?

Captive Dependencies
06:46

A discussion of how objects are cleaned up when created in different scopes.

Disposal
04:07

You can catch events related to lifetime changes on a component.

Preview 09:58

Learn about startable components.

Running Code at Startup
03:05

A summary of all the things we've learned in this section of the course.

Summary
07:32

Test your comprehension by answering these questions.

Scope and Lifetime Quiz
5 questions
+ Configuration
7 lectures 34:28

A look at the things we'll encounter in this section of the course.

Overview
01:05

What's the point of modules when we have individual components?

Why Modules?
09:04

A live demo of how modules are defined and used.

Using Modules
07:26

Using Microsoft Configuration Extensions, you can configure the Autofac container externally using an XML or JSON file.

JSON/XML Configuration with Microsoft Configuration
08:08

A look at some of the options for configuring your components in XML/JSON files.

Component Options
04:27

A look at how to configure modules in XML or JSON files.

Configuration of Modules
01:58

A summary of the things we've learned in this section.

Summary
02:20

Check your comprehension by answering a few questions.

Configuration Quiz
3 questions
+ Advanced Topics
9 lectures 01:05:55

A look at the things we'll encounter in this section of the course.

Overview
01:38

Customize the container by specifying additional classes that provide their own custom registrations. 

Registration Sources
15:54

Automatically register adapters; if Foo is an adapter for IBar, ensure that c.Resolve<IList<Foo>>() gets several instances of Foo, one for each available IBar.

Adapters
09:07

If Foo implements IFoo but Bar also implements IFoo and is a decorator of Bar, ensure that requests for an IFoo yield a Bar that is injected an instance of Foo.

Decorators
06:10

Can two components reference each other and be resolved correctly by the container?

Circular Dependencies
08:13

Metadata can be provided using Meta<T>, but thanks to Autofac's MEF integration, you can also attach it to classes using attributes, and then use other attributes to perform filtering on this metadata.

Attribute Based Metadata
06:04

What happens when your component depends on too many other components? Can we avoid having a super-long constructor?

Aggregate Services
09:15

Leveraging the power of Castle.DynamicProxy to do some aspect-oriented programming.

Type Interceptors
08:09

A summary of all the things we've learned in this section of the course.

Summary
01:25

Final set of questions to test your comprehension of advanced topics.

Advanced Topics Quiz
6 questions
+ End of Course
3 lectures 08:58

A look at how to start using Autofac with ASP.NET MVC projects.

ASP.NET MVC Integration
07:12

A summary of the the things we've learned in this course and where to get more info.

Course Summary
01:33
Bonus Lecture: Other Courses at a Discount
00:13
Requirements
  • Confident knowledge of C# and .NET
  • Good knowledge of object-oriented programming principles
  • Confident use of an IDE (e.g., Visual Studio)
Description

This is a course covering Dependency Injection in .NET using the Autofac library. The goal of the course is to provide in-depth coverage of the concept of dependency injection and give examples of how DI/IoC is used in the modern world.

This course covers the following topics:

  • The concepts of Dependency Injection and Inversion of Control and what they are for
  • Components and Services (terminology used by the Autofac container)
  • Component Registration including assembly and module scanning
  • Controlling Scope and Lifetime
  • Configuration including XML/JSON and Modules
  • Plenty of advanced topics for the connoisseur 



    Who this course is for:
    • Beginner and Experienced .NET/C# Developers
    • Anyone interested in modern approaches to Dependency Injection