Last active
August 29, 2015 14:13
-
-
Save devdays/2e2670771348ce32954c to your computer and use it in GitHub Desktop.
Simple Injector container initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Http; | |
using SimpleInjector; | |
using SimpleInjector.Integration.WebApi; | |
using Interfaces; | |
using Common; | |
public static class SimpleInjectorWebApiInitializer | |
{ | |
// Make container available to the rest of the application | |
// Use Container to instantiate the objects you want | |
public static Container Container = new Container(); | |
/// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary> | |
public static void Initialize() | |
{ | |
InitializeContainer(Container); | |
Container.RegisterWebApiControllers(GlobalConfiguration.Configuration); | |
Container.Verify(); | |
GlobalConfiguration.Configuration.DependencyResolver = | |
new SimpleInjectorWebApiDependencyResolver(Container); | |
} | |
private static void InitializeContainer(Container container) | |
{ | |
// Set your instances to use automatic constructor injection here | |
// Container.RegisterWebApiRequest<IUserRepository, SqlUserRepository>(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment