RSS

Dependency Injection in Web API With Unity IoC

18 Nov

WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        var container = new UnityContainer();
        container.RegisterType<IProductRepository, ProductRepository>();
        config.DependencyResolver = new UnityResolver(container);

        // Other Web API configuration not shown.
    }
}

Global.asax.cs

protected void Application_Start()
{
    // Some code here...

    WebApiConfig.Register(GlobalConfiguration.Configuration);

    // Some code here...
}

Version attow: Unity 3, Web API 2

Advertisements
 
Leave a comment

Posted by on November 18, 2014 in General

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: