Unity Examples

by ldlarsed
+

Collection of examples for dependency injection with Microsoft Unity Framework

( Updated an hour ago )

Unity_Examples

Collection of examples for dependency injection with Microsoft Unity Framework

UnityExample1 - Console

Simple example using a instances of two board games (TrivialPursuit and TicTacToe). Contains both direct and indirect injection types. Follwing example is a console based application. Double tap Enter to forward to the next game instance.

  • Nu.Get packages: Unity (the basic unity package)

Source

UnityExample2 - WebAPI

This an simple WebAPI (empty Web application project with support for WebABI and MVC structure).

  • Nu.Get packages: Unity.WebAPI (and all of it's dependencies)
  • Api is accessible from the following url: http://localhost:15192/api/Values.
  • Own configurations is commented with //My own configuration.

Following configurations are added:

  • Global.asax.cs
   UnityConfig.RegisterComponents();
  • UnityConfig.cs
   container.RegisterType<Models.Person.IPerson, Male>("Male");
   container.RegisterType<Models.Person.IPerson, Female>("Female");

Source

UnityExample3 - MVC

Following configurations are added:

  • Global.asax.cs
   UnityConfig.RegisterComponents();
  • UnityConfig.cs
   container.RegisterType<ICourseService, CourseService>();
   container.RegisterType<IInstitutionService, InstitutionService>();

Source