使用DI

Unit

參考的文章

var container = BuildUnityContainer(); 

DependencyResolver.SetResolver(new UnityDependencyResolver(container)); 

GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); 

return container;

HierarchicalLifetimeManager

http://www.asp.net/web-api/overview/advanced/dependency-injection

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

    // Other Web API configuration not shown.
}

results matching ""

    No results matching ""