ioc container - How to iterate over Ninject StandardKernel's configured bindings to debug? -
in ninject binding module,
public class carmodule : ninjectmodule { public override void load() { kernel.bind(scanner => scanner.fromthisassembly().selectallclasses() .inheritedfrom<icar>().bindallinterfaces()); foreach (var binding in kernel.getbindings(typeof(icar))) { trace.writeline(string.format("[{0}] service bound [{1}]", binding.service.name, binding.target.gettype().name)); } // output looks like: //[icar] service bound [bindingtarget] //[icar] service bound [bindingtarget] //[icar] service bound [bindingtarget] } }
i need sanity check see types i've bound services. i'm having trouble accessing type names of bound types. instead of [bindingtarget]
, i'd see [mercedes]
, [ferrari]
, etc...
is there and/or common way this?
in iockernel, d add method getall instances of given type t, , call after loading module:
public static class iockernel { private static standardkernel _kernel; public static ienumerable<t> getall<t>() { return _kernel.getall<t>(); } public static void initialize(params ininjectmodule[] modules) { if (_kernel == null) { _kernel = new standardkernel(modules); list<icar> bindingslist= _kernel.getall<icar>().tolist(); foreach(icar binding in bindingslist) { trace.writeline(string.format("service bound [{1}]", binding.gettype().name) } } } }
Comments
Post a Comment