Practical IoC With ASP.NET MVC 4

In this course, we'll learn how to use an IoC container, like Unity in an ASP.NET MVC 4 application and some of the basics of the practical application of IoC containers.
Course info
Rating
(981)
Level
Intermediate
Updated
Aug 26, 2013
Duration
2h 15m
Table of contents
Description
Course info
Rating
(981)
Level
Intermediate
Updated
Aug 26, 2013
Duration
2h 15m
Description

At first, Inversion of Control (IoC) is a difficult concept to understand. Even after understanding what IoC is, a developer must learn to apply the concepts of IoC and IoC containers to a real application in order to use it effectively. In this course, John will show you how to use the Unity IoC container in an ASP.NET MVC 4 application to use dependency injection on controllers, filters, views and more. You’ll start off by learning the basics of IoC containers, how they work and why they are important. As well as, learning about how internally ASP.NET MVC 4 creates controllers and views. In order to understand practically how dependency injection works (the core function of IoC containers)John will walk you through manually doing dependency injection in ASP.NET MVC 4 using your own custom controller factory. After you have done things manually, you’ll see how to add the Microsoft Unity IoC container to your MVC 4 application to do dependency injection automatically. Essentially you'll see how it is able to give us more flexibility and reduce the custom code we need to write. John then takes things even further by exploring some advanced dependency injection techniques using Unity to inject views and filters. He’ll also cover some of the advanced features of the Unity IoC container. Finally, you’ll take a tour through some other popular .NET IoC containers and see how to get them working in our ASP.NET MVC 4 application. After taking this course you will be equipped with the skills and knowledge you need to build real applications using Inversion of Control and dependency injection.

About the author
About the author

John Sonmez is the founder of Simple Programmer (http://simpleprogrammer.com), where he tirelessly pursues his vision of transforming complex issues into simple solutions

More from the author
Beginning Lua
Intermediate
2h 50m
2 Dec 2013
Beginning HTML 5 Game Development With Quintus
Intermediate
2h 52m
25 Oct 2013
Beginning HTML5 Apps For Firefox OS
Intermediate
2h 20m
17 Oct 2013
More courses by John Sonmez
Section Introduction Transcripts
Section Introduction Transcripts

Introduction
Hi, this is John Sonmez from Pluralsight and welcome to this course on practical IoC with ASP. NET MVC 4. Concepts like IoC in dependency injection can be a bit difficult for developers to grasp and even after grasping the concepts, it is usually not readily apparent how to apply those concepts to a real application. The goal of this course is to show you how to practically apply IoC to an ASP. NET MVC 4 application to inject dependencies in the controllers, views and even filters. We'll also tackle some of the nonstandard cases of dependency injection like parameterize injection and learn how to manually do dependency injection in MVC 4 to really understand what's going on. By the end of this course, you should feel confident in your ability to use dependency injection in ASP. NET MVC 4 applications.

Doing It Yourself
Hi, this is John Sonmez from Pluralsight and in this module we'll be learning how to do manual dependency injection with our existing MVC 4 application. It's pretty easy to just plug in an IoC container in an ASP. NET MVC 4 application but not really understand what's going on and how it's working. Often developers can get dependency injection working by following some steps in an online tutorial or blog post but in order to really make the best use of an IoC container that does dependency injection for us. It's important to understand why exactly we would want to use it and how it works. Basically what problem is it trying to solve. In this module I'll take you step by step through the process of manually setting up dependency injection in ASP. NET MVC by first showing you why we need it and the benefit we get from it and then showing you how to convert our existing application to use inversion of control and finally, create a custom controller factory to actually inject dependencies into our controller. By the end of this module, you should be able to identify the reasons for using dependency injection, know how to refactor an application to make use of it and understand how to create a custom controller factory to control the process of creating controllers in ASP. NET MVC 4.

Injecting With Unity
Hi, this is John Sonmez from Pluralsight. And in this module, we're gonna be converting our MVC application to use Unity for dependency injection instead of using the manual injection we did previously with our own controller factory. Now that you understand how to manually create controllers in ASP. NET MVC and how to inject dependencies manually, it'll be much easier to see and understand the value of using an IoC container like Unity. In this module, I'll show you how you can get Unity setup in your ASP. NET MVC application and use it to replace the default dependency resolver that is used to resolve dependencies in MVC. We'll be using a different extension point in MVC to do our injection with Unity, but the same basic ideas will still apply.

Advanced Injection
Hi, this is John Sonmez from Pluralsight and in this module, we'll be learning how to do some advanced injection techniques in ASP. NET MVC 4 using Unity. We'll start off by learning how to do injection in views. We can inject dependencies directly into a view instead of passing them through the controller, but in order to do this, we'll have to make use of property injection, which I'll show you how to do. Then we'll see how to add global filters to our actions and allow for those filters to have dependencies injected in them as well. Finally, I'll show you some of the advanced ways you might use the Unity container in your application to do things like manually a constructor parameter to a type or even make which implementation of an interface that is used configurable by using named registrations. By the end of this module, you should know enough about dependency injection in MVC to be able to handle most cases you would encounter in a real world application.

Using Other IoC Containers
Hi, this is John Sonmez from Pluralsight and in this module I'm going to show you how to get some of the other popular IoC containers working with asp. net MVC 4. So far in this course, we've been using Unity. And while Unity is a perfectly good IoC container, you may want to use another IoC container or you may be working on a project that has already chosen a particular IoC container to use so you'll have to figure out how to get it to work. In this module, I'll take you through the process of getting an inject, Structure Map, Autofac, Castle Windsor, and the new Simple Injector IoC containers to work with asp. net MVC 4. As you'll see, some of these IoC containers can be easily set up with a NuGet package, but a few of them will require a bit of additional work. Even if you're planning on using Unity, you'll probably find that learning how to configure other IoC containers in MVC will reveal a bit more to you about how the MVC pipeline works and some different strategies and techniques for doing dependency injection.