Skip to content

Autofac diagnostics support to enable DOT graph visualization of resolve requests.

License

Notifications You must be signed in to change notification settings

autofac/Autofac.Diagnostics.DotGraph

Repository files navigation

Autofac.Diagnostics.DotGraph

Autofac diagnostics support to enable DOT graph visualization of resolve requests.

Build status

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Quick Start

After building your container, attach the Autofac.Diagnostics.DotGraph.DotDiagnosticTracer to the container. When every resolve operation completes (success or failure) you'll get a trace. It's up to you to determine what to do with that trace - write it to a file, render it to an image, etc.

// Build a container with some registrations.
var containerBuilder = new ContainerBuilder();
containerBuilder.Register(ctx => "Hello");
var container = containerBuilder.Build();

// Attach a DotDiagnosticTracer to the container.
// Handle the OperationCompleted event to deal
// with the trace output.
var tracer = new DotDiagnosticTracer();
tracer.OperationCompleted += (sender, args) =>
{
  using var file = File.OpenWrite(Guid.NewGuid().ToString() + ".dot");
  using var writer = new StreamWriter(file);
  writer.WriteLine(args.TraceContent);
};
container.SubscribeToDiagnostics(tracer);

// Resolve some things and look at the graphs!
// You can use graphviz to render a PNG like:
// dot -T png -O filename.dot
using var scope = container.BeginLifetimeScope();
scope.Resolve<string>();

Tracing graphs is expensive! Getting a graph trace is convenient but does have a performance and memory/resource impact. It's recommended you only enable this in a development/troubleshooting situation.

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

About

Autofac diagnostics support to enable DOT graph visualization of resolve requests.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •