generating dependency graph from Ninject container

224 views
Skip to first unread message

fschwiet

unread,
Jul 18, 2010, 9:26:15 PM7/18/10
to ninject
Does anyone know a way to get the dependency graph for a Ninject
container? IE, I would like to enumerate the services renderred, see
what class is registered for that service, and see what dependencies
that class has.

Sorry for all the posts today :) This is a weekend project so
volume will go down tomorrow.

piotr...@gmail.com

unread,
Aug 27, 2010, 8:01:14 AM8/27/10
to ninject
I'd be very interrested in that too.
Can someone please point us to a solution or give some directions on
how to implement it.

On 19 Lip, 03:26, fschwiet <fschw...@gmail.com> wrote:
>   Does anyone know a way to get thedependencygraphfor a Ninject

piotr...@gmail.com

unread,
Aug 27, 2010, 7:57:21 AM8/27/10
to ninject
I'd be very interrested in that too.
Can someone please point us to a solution or give directions on how to
implement it.

On 19 Lip, 03:26, fschwiet <fschw...@gmail.com> wrote:

fschwiet

unread,
Aug 27, 2010, 10:13:13 PM8/27/10
to ninject
I have a rudimentary implementation on my branch: http://github.com/fschwiet/ninject

It works best for dependencies that map to a service where Ninject
instantiates it, as in that case it has the name of the service to
show. Rather then the standard kernel, you need to use
DependencyGraphingKernel().

You can then do something like this to print the graph:

public void WriteDependencyGraph(DependencyGraphingKernel
kernel, System.IO.TextWriter writer)
{

DependencyGraphTraversal.VisitGraph(kernel.LoadSupportedServices(),
new PrintingDependencyGraphVisitor(writer));
}

Here is some sample output:

ResetPasswordController
FormsAuthentication (IFormsAuthentication)
UserService (IUserService)
ResetPasswordService (IResetPasswordService)
GuidGenerator (IGuidGenerator)
UserEmailer (IUserEmailer)
SitePolicy (ISitePolicy)
ConstantProvider{Object} (ISiteInfo)
TemplateRepository (ITemplateRepository)
UserService (IUserService)
Mail (IMail)
ResetPasswordRoutes (IResetPasswordRoutes)
SiteInfoExtensions (ISiteInfoExtensions)
ConstantProvider{Object} (ISiteInfo)



On Aug 27, 4:57 am, "PiotrOws...@gmail.com" <piotrows...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages