Global.asax中的服务定位器

时间:2014-02-21 11:04:17

标签: asp.net-mvc-3 global-asax ninject.web.mvc service-locator

我的Global.asax中有几个部分需要使用

之类的东西
var myServiceInstance = Kernel.Get<IMyServiceInterface>();

应用程序是MVC3,服务定位器是NInject 2.2.0.0。但是,从NInject 2.1.0.0升级时,内核属性已过时,并声明不应将NInject用作服务定位器。

我非常愿意遵从这一点,但我需要一些指导。谁能告诉我新方法应该是什么?

我在Global.asax中使用服务位置,因为我需要访问数据库。这是唯一的固定要求。

L.E:在这种情况下,属性注入是一种解决方案吗?

1 个答案:

答案 0 :(得分:1)

我提出了这个解决方案,因为属性注入不是解决方案:

var myServiceInstance = DependencyResolver.Current.GetService<IMyServiceInterface>();

这可以接受吗?