ninject 和企业库服务定位器依赖程序集
我将 Microsoft.Practices.ServiceLocation 程序集与 ninject 结合使用以帮助进行服务定位。我将 ninject 内核注册到 servicelocator 提供程序方法中:
var kernel = new StandardKernel();
//do bindings
var locator = new NinjectServiceLocator(kernel);
ServiceLocator.SetLocatorProvider(() => locator);
上面的代码在安装了企业库(通过 msi 可执行文件)的计算机上都运行良好。我无法在生产中运行安装程序,因此我将 dll 本地放在 bin 目录中,希望这能起作用。然而它不起作用。我没有得到任何未找到程序集的异常,而是从调用“at Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()”时得到了对象引用未设置异常。
我在一些地方读到该程序集没有任何依赖项 http://msdn.microsoft.com/en-us/library/ff664422%28v=PandP.50%29.aspx 和本地dll 应该可以解决问题,但似乎没有。
我已经在几个盒子上进行了测试,并且错误一直发生,直到我运行安装程序。有趣的是,在我卸载该库后,它仍然有效(我猜它缓存在某处)。
有人对此类问题有任何经验吗?
I am using the Microsoft.Practices.ServiceLocation assembly in conjunction with ninject to aid in service loaction. I register my ninject kernel into the servicelocator provider method:
var kernel = new StandardKernel();
//do bindings
var locator = new NinjectServiceLocator(kernel);
ServiceLocator.SetLocatorProvider(() => locator);
The above code all works fine on machines that have the enterprise library installed (via the msi executable). I am not in a position to run the installer in production, so i have the dll locally in the bin directory, hoping this will work. However it does not work. I dont get any assembly not found exceptions, instead i get an object reference not set exception from call to: 'at Microsoft.Practices.ServiceLocation.ServiceLocator.get_Current()'.
I have read in a few places that this assembly doesn't have any dependencies http://msdn.microsoft.com/en-us/library/ff664422%28v=PandP.50%29.aspx and a local dll should do the trick, but it doesnt seem to.
I've tested on a few boxes and the error occurs consistently until i run the installer. Interestingly, after i uninstall the library, it still works (i guess it's cached somewhere).
Has anyone got any experience with type of issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题原来是 servicelocator.current 是空的,因为我自动注册的绑定模块之一缺少 dll。因为引导程序是从 global.asax 调用的,所以我进行了错误处理,应该记录任何异常并继续(不希望整个站点因这一页而停止)。所以我从来没有遇到过注册错误,并且我的引导程序在没有告诉我的情况下失败了。
the issue turned out to be that the servicelocator.current was empty because one of the binding modules i was auto registering was missing a dll. because the bootstrapper was being called from the global.asax i had error handling that was supposed to be logging any exceptions and continuing (wouldnt want the whole site to stop for this one page). so i never got the reg error and my bootstrapper was failing without telling me.