Object graph visualization using VisualizeObjectGraph produces incomplete result for IEnumerable<> dependecies
See original GitHub issueVisualizeObjectGraph
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:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 theContainerControlledCollection
produceKnownRelationship
instances that are flagged asUseForVerification = false
. This allows the elements of aContainerControlledCollection
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.
This bug has been fixed in v4.9.1.