// create a container UnityContainer container = new UnityContainer(); // register a type for interface IUserRepository container.RegisterType(); // resolve the type with interface dependency IUserRepository userRepository = container.Resolve ();
// create a container UnityContainer container = new UnityContainer(); // register a singleton instance of UserManager UserManager userManager = new UserManager(); container.RegisterInstance(userManager); // resolve the instance UserManager resolvedUserManager = container.ResolveIn this example, the UnityContainer is used to register an instance of UserManager as a singleton. Later, the container is used to resolve the singleton instance of UserManager. The Microsoft.Practices.Unity package library provides a range of features for DI and IoC in C#.();