c# - Catel/Ninject: Ninject.ActivationException when resolving IUIVisualizerService -
when trying resolve iuivisualizerservice ninject.activationexception came in ninject.dll.
can me pls?
this code section calls problem:
ninjectdependencyresolver resolver = new ninjectdependencyresolver(); var item = resolver.getservice<iuivisualizerservice>();
code resolver:
using system; using system.collections.generic; using catel.services; using ninject; using nlog; namespace ms_modell.infrastructure { internal class ninjectdependencyresolver { private ikernel kernel; private logger log = logmanager.getcurrentclasslogger(); public ninjectdependencyresolver() { try { kernel = new standardkernel(); kernel.bind<iuivisualizerservice>().to<uivisualizerservice>(); } catch (exception ex) { log.fatal("ninjectdependencyresolver(): " + ex); throw; } } public t getservice<t>() { try { return kernel.tryget<t>(); } catch (exception ex) { log.fatal("getservice<t>(): " + ex.message); throw; } } } }
edit: got null object after getservice called. exception wasnt raised. message on console output of visual studio can seen:
an expcetion (first chance) of type "ninject.activationexception" thrown in ninject.dll.
edit 2:
thx guys fast answers. here concrete solution someone, runs same problem:
in ninjectresolver need add code:
kernel.bind<iviewlocator>().to<viewlocator>(); kernel.bind<iuivisualizerservice>().to<uivisualizerservice>().withconstructorargument("viewlocator", getservice<iviewlocator>());
resolving iuivisualizerservice:
targetselectorviewmodel selector = new targetselectorviewmodel(); var item = resolver.getservice<iuivisualizerservice>(); item.register(typeof(targetselectorviewmodel), typeof(targetselector)); item.showdialog(selector);
the uivisualizerservice requires dependency injection of iviewlocator. make sure ninject can resolve well.
Comments
Post a Comment