ninject - Error when disposing a IActivationBlock and importing IKernel -
the problem started when trying use solution below use ninject 3 mvc 4 rc web api project:
http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/
this solution uses iactivationblock (created beginblock method ikernel) implement scope of calls. regular ninject project, seems work fine, when project uses extension ninject.extensions.interception.dynamicproxy, following exception occurs when dispose method of activation block called:
error loading ninject component iadviceregistry
no such component has been registered in kernel's component container.
and, in next time when new activationblock created , resolve method called, following exception occurs:
error loading ninject component icache
no such component has been registered in kernel's component container.
it seems problem not directly related mvc update, incompatibility between dynamicproxy , iactivationblock.
edit:
the source of problem when 1 of types requires ikernel on constructor, , it's not directly related dynamicproxy, first exception occurs when references assembly.
so, second error (related icache) occurs if type requires ikernel.
to summerize nice analysis: create instance of class inside activationblock has dependancy on ikernel directly.
this logical flaw, idea of activationblock "restore state" of kernel after block disposed , instance has access kernel , can change unrevertably of bindings. (yes, instance idisposable cleans after self; there no logical flaw -- unusual use case).
my experiance vast majority of these uses call ikernel.get<...>(...) , friends. valid inside activationblock: requesting more need: ikernel instead of iresolutionroot (e.g. don't need ibindingroot of ikernel). change types in class , fine.
p.s. analysis source of exception. helped me own problem.
Comments
Post a Comment