skip to the main content area of this page
Patterns and Practices

Unity Dependency Injection IoC Screencast


Unity Dependency Injection Container

Unity IoC Screencast

The Unity Dependency Injection / IoC Container is new from Microsoft Patterns and Practices. It will come in both a stand-alone version and bundled within Enterprise Library 4.0 as an alternate configuration mechanism for the application blocks. This screencast shows several common usages of Unity as well as how to use Unity with both the ASP.NET MVC Framework and with ASP.NET Webforms using Model-View-Presenter.

The screencast highlights:

  • ASP.NET MVC Framework.
  • ASP.NET Model View Presenter Pattern.
  • UnityContainer Resolve and BuildUp Methods
  • UnityContainer RegisterType and RegisterInstance Methods
  • UnityConfigurationSection for Web.config and App.config

Download ( 30MB, 22min WMV File )



Unity Dependency Injection IoC Screencast Show Notes

In addition to showing real-world usage of the Unity IoC / Dependency Injection Container in:

  •  ASP.NET Webform applications using Model-View-Presenter
  • ASP.NET MVC Framework via a Custom Unity Controller Factory

The screencast shows several common usages of the Unity IoC, such as:

  • Creating Types Not In Container
  • Registering and Resolving TypeMappings
  • Registering and Resolving Named TypeMappings
  • Singletons, LifetimeManagers, and the ContainerControlledLifetimeManager
  • Registering Existing Instances
  • Injecting Dependencies into Existing Instances
  • Populating the UnityContainer via App.config / Web.config
  • Specifying Dependencies via Injection API as opposed to Dependency Attributes
  • Using Nested ( Parent-Child ) Containers

It shows several examples of the UnityContainer API:

  • UnityContainer.RegisterType<ILogger,NullLogger>();
  • UnityContainer.RegisterType<Database,SqlDatabase>();
  • UnityContainer.RegisterType<Database,OracleDatabase>("Oracle");
  • IEnumerable<Database> databases = UnityContainer.ResolveAll<Database>();
  • ILogger logger = UnityContainer.Resolve<ILogger>();
  • Database database = UnityContainer.Resolve<Database>("SQL");
  • UnitContainer.RegisterInstance<Database>("SQL",new SqlDatabase());
  • UnityContainer.BuildUp(existingDatabase);
  • IUnityContainer childContainer1 = parentContainer.CreateChildContainer();
  • etc...

You can find the blog posts with code samples for this screencast at the following links:

 


Tags: DependencyInjection, EnterpriseLibrary4, IoC, Unity


Topics



Popular Tags



Recent Links