Unity - Dependency Injection Types

You can use RegisterType or App.config to achieve the same objectives.

static void Main(string[] args)
IUnityContainer container = new UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

//// You can override with container.RegisterType();

CoreService svc = container.Resolve();

Sample Service classes

public class CoreService
public IService MyService { get; set; }

public void ExecuteService()


public class CustomerService : IService

string IService.SayHello(string Username)
return "Customer Service " + Username;

Sample App.Config File

<?xml version="1.0" encoding="utf-8" ?>
<section name="unity"
Microsoft.Practices.Unity.Configuration" />
<type type="Services.IService, Services" mapTo="Services.CustomerService, Services"></type>


Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners

OpenCover code coverage for .Net Core