JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
563 stars 118 forks source link

Elaborate better exception message when a parameter is missing #379

Closed matiassilioni closed 10 months ago

matiassilioni commented 1 year ago

Hey, I've been through this error a few times, so I consider that the exception message should give more details.

In this case, I have a string parameter, which wasn't provided in the DI configuration by mistake, so in runtime, it failed. The exception is just showing the parameter name, but not the constructor or type. When the DI is way big, it's super hard to trace which class/constructor is misconfigured.

To find it I had to pull the source and add it to my solution to finally debug it and figure it out.

Note that neither the exception message nor the stack trace displays relevant information.

image

The proposed solution, log the parameter.Member.DeclaringType property too

image

To finally have something like this:

image

jeremydmiller commented 1 year ago

@matiassilioni,

This is going to be an "I take pull requests". If you have a specific recommendation though, I'm all ears.

In the meantime, I strongly recommend against directly injecting primitive values like strings, numbers, Uris. My personal approach is to use strong typed settings or options classes instead. That might help a bit.