question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object graph visualization using VisualizeObjectGraph produces incomplete result for IEnumerable<> dependecies

See original GitHub issue

VisualizeObjectGraph does not include component types that are part of IEnumerable<> dependency.

How To Reproduce

Consider the following registrations:

var container = new Container();

container.Collection.Register(typeof(IValidator<>), typeof(IValidator<>).Assembly);
container.Register(typeof(IValidator<>), typeof(CompositeValidator<>));
container.Register<MyService>();

container.Verify();

var actual = container.GetRegistration(typeof(MyService)).VisualizeObjectGraph();

Console.WriteLine(actual);

Using types:

class MyService { public MyService(IValidator<MyModel> myModelValidator) { } }

interface IValidator<T> { }

class Composite<T> : IValidator<T> { public Composite(IEnumerable<IValidator<T>> v) { } }

class Validator1 : IValidator<MyModel> { public Validator1(Dependency d) { } }
class Validator2 : IValidator<MyModel> { public Validator2(Dependency d) { } }

class Dependency { }

class MyModel { }

Prints to the console

MyService( // Transient
    Composite<MyModel>( // Transient
        IEnumerable<IValidator<MyModel>>( // Singleton
            Dependency(), // Transient
            Dependency()))) // Transient

Expected to print

MyService( // Transient
    Composite<MyModel>( // Transient
        IEnumerable<IValidator<MyModel>>( // Singleton
            Validator1( // Transient
                Dependency()), // Transient
            Validator2( // Transient
                Dependency())))) // Transient

Additional context

  • SimpleInjector 4.7.1
  • .NET Core 3.0 console app

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dotnetjunkiecommented, Mar 4, 2020

Wow, that was quite a ride. I’ve been digging deep into this again today and am happy to announce that I was able to fix the problem. And with it, several small bugs surrounding the creation of KnownRelationship types concerning collection elements. That part was a bit a mess. Although there were quite a few tests concerning this part of the system, horrifically enough, those tests just echoed what the system was doing, instead of verifying what the system should have been doing. In other words, there were tests that tested the wrong behavior. Nice.

I was able to fix the problem by added an internal flag to KnownRelationship and by letting the ContainerControlledCollection produce KnownRelationship instances that are flagged as UseForVerification = false. This allows the elements of a ContainerControlledCollection to be used for visualization purposes, while being skipped when it comes to diagnostics. In other words, there is now a distinction between “visualization only” and “visualization and verification” registrations.

https://github.com/simpleinjector/SimpleInjector/commit/926563f239efd67f22a0c09ead94a0c9767269a1 shows the complete change.

0reactions
dotnetjunkiecommented, Mar 6, 2020

This bug has been fixed in v4.9.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection best practice when new object graph ...
1 Answer. according to the book Dependency Injection in . NET states that the object graph is created once at app startup in...
Read more >
ig.scheduler.ScheduleDataSource - API Reference - Ignite UI
ScheduleDataSource provides the ability to bind the Scheduler to a source of data from which Appointment and ScheduleResource objects can be created, updated, ......
Read more >
Grasp - Executable Intent
Any graph with a cycle will result in a compilation error from Grasp. To create the nodes, we add a method to the...
Read more >
StructureMap – Page 2 – The Shade Tree Developer
We're keeping the behavior graph model for specifying which middleware goes where, but this time we're planning to use Roslyn to compile code...
Read more >
FnuPlot: Cross-platform charting with gnuplot
The library is incomplete and I don't expect to dedicate too much time to maintaining it, but it works quite nicely for basic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found