简体   繁体   中英

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. 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?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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