Skip to content

Resources for "Leveling Up: Dependency Injection in C#" workshop - samples using .NET 6.0

License

Notifications You must be signed in to change notification settings

jeremybytes/di-dotnet-workshop-2022

Repository files navigation

Dependency Injection in C# [Full-Day Workshop]

Description

Loosely coupled code is easier to maintain, extend, and test. Dependency Injection (DI) help us get there. In this workshop, we'll see how interfaces can add "seams" to our code that makes it more flexible and maintainable. From there, we'll dig into loose coupling with Dependency Injection. DI doesn't have to be complicated. With just a few simple changes to our constructors or properties, we can have code that is easy to extend and test.

After laying a good foundation, we'll take a closer look by diving into various DI patterns (such as constructor injection and property injection) as well as other patterns that help us handle interception and optional dependencies. Along the way, we'll see how DI helps us adhere to the SOLID principles in our code. We'll also we'll look at common stumbling blocks like dealing with constructor over-injection, managing static dependencies, and handling disposable dependencies.

Throughout the day, we'll go hands-on with labs to give you a chance to put the concepts into action.

If you're a C# developer who wants to get better with concepts like abstraction, loose coupling, extensibility, and unit testing, then this is the workshop for you.


Pre-requisites

To get the most out of the workshop, you should have an understanding of the basics of C# and object oriented programming (classes, inheritance, methods, and properties). No prior experience with dependency injection is necessary. Hardware & Software To participate in the hands-on portion, you will need a computer (Windows, macOS, or Linux) with the following installed:

As an alternative to Visual Studio Code, you can use Visual Studio 2022 (any edition).


Labs

These are the hands-on portions of the workshop. Labs can be completed with Visual Studio Code or Visual Studio 2022. All labs run on Windows, macOS, and Linux. Each lab consists of the following:

  • Labxx-Instructions (Markdown)
    A markdown file containing the lab instructions. This includes the scenario, a set of goals, and step-by-step instructions.
    This can be viewed in on GitHub or in Visual Studio Code (just click the "Open Preview to the Side" button in the upper right corner).

  • Starter (Folder)
    This folder contains the starting code for the lab.

  • Completed (Folder)
    This folder contains the completed solution. If at any time, you get stuck during the lab, you can check this folder for a solution.


Topics + Code

The following connects the topics with the sample code.

Basics

Constructor Injection

Object Composition / Composition Root

  • Program.cs - Web application program file (no DI container)
  • App.xaml.cs - Desktop application main window (no DI container)
  • App.xaml.cs - Desktop application main window (using Ninject)

Decorators

Unit Testing

Dependency Injection Containers

  • App.xaml.cs - Desktop application main window (using Ninject)

Property Injection

Deeper Dive / Advanced Topics

Property Injection

Method Injection

Read-Only / Guard Clause

Decorators

Proxy / IDisposable

Static Dependencies

Configuration Strings


Resources

DI Patterns

Decorators and Async Interfaces

Challenges

Related Topics

More information at http://www.jeremybytes.com


About

Resources for "Leveling Up: Dependency Injection in C#" workshop - samples using .NET 6.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages