简体   繁体   English

ninject和企业库服务定位器依赖的程序集

[英]ninject and enterprise library service locator dependant assemblies

I am using the Microsoft.Practices.ServiceLocation assembly in conjunction with ninject to aid in service loaction. 我将Microsoft.Practices.ServiceLocation程序集与ninject结合使用,以帮助进行服务。 I register my ninject kernel into the servicelocator provider method: 我将我的ninject内核注册到servicelocator提供程序方法中:

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). 上面的代码在安装了企业库的计算机上都可以正常运行(通过msi可执行文件)。 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. 我无法在生产环境中运行安装程序,因此我在bin目录中本地拥有该dll,希望这可以正常工作。 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()'. 我没有得到任何未找到的程序集异常,而是从调用“在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. 我已经在几个地方阅读过,该程序集没有任何依赖关系http://msdn.microsoft.com/zh-cn/library/ff664422%28v=PandP.50%29.aspx ,本地dll应该可以把戏,但似乎没有。

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? 有没有人对这类问题有经验?

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. 问题原来是servicelocator.current为空,因为我正在自动注册的绑定模块之一缺少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). 因为引导程序是从global.asax调用的,所以我进行了错误处理,该错误处理应该记录任何异常并继续进行(不希望整个网站停止此页面)。 so i never got the reg error and my bootstrapper was failing without telling me. 所以我从来没有遇到过reg错误,而我的引导程序却在没有告诉我的情况下失败了。

var kernel = new StandardKernel();
//do bindings -> throw error here without reaching below two lines to regiester the service locator
var locator = new NinjectServiceLocator(kernel);
ServiceLocator.SetLocatorProvider(() => locator);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM