Calls to retrieve an IEnumerable of a type that is not registered call the constructor of said type.
I'm attempting to get Quartz working in a project.
The startup code for Quartz makes a few calls like the following
serviceProvider.GetServices<JobListenerConfiguration>();
This results in call to
serviceProvider.GetRequiredService<IEnumerable<JobListenerConfiguration>>();
There is nothing registered for JobListenerConfiguration. When running this code in a project without grace, this results in an empty array of JobListenerConfiguration being returned. I don't believe anything is specifically registering that as a service.
On the other hand grace attempts to locate and inject parameters into JobListenerConfiguration, which fails because one of the parameters is just Type listenerType
I've worked around this by specifically registering an empty enumerable for IEnumerable<JobListenerConfiguration> which was complicated by JobListenerConfiguration being an internal type.
Not sure if this is a bug exactly, but I think ideally grace would also return an empty enumerable and not try to figure out how to inject services into the constructor of a type that is not registered with it when the request is for a collection of said type.
Hey, hi @belav! Funny to see you here.
This is a feature of Grace that is historically enabled by default. With increased DI adoption since .net core, it shows up as a footgun more and more often.
Grace has an option AutoRegisterUnknown that is true by default. I highly advise you to turn it off.
If you can't, there's ExcludeTypeFromAutoRegistration to opt-out for specific types.
More and more libs use advanced patterns such as looking for optional registrations and this trips a lot of users. Others have had issues with MassTransit #309, Orleans #315, OpenTelemetry #317.
This is a feature of Grace that is historically enabled by default. With increased DI adoption since .net core, it shows up as a footgun more and more often.
If I had to do it again I'd probably leave the feature out as now it causes more confusion than it helps :(
@ipjohnson if you do a major v8 release for .net 8, maybe change the default from true to false as a breaking change?
It will help newcomers, and people who upgrade can opt-in if they depend on it.
I'll be honest I've changed jobs and stopped using .net for work about 3+ years ago. Since then I just haven't had the time or need to work on Grace. I'd be interested in handing it over to someone that has some time to care for it.
Any thoughts on how best to turn over the reins?
@ipjohnson Thanks for letting us know, and congrats on your new job! I hope you're having fun!
I have no experience in transferring OSS projects. Although I have previously made contributions to Grace, I personally do not have the time to take it over.
Grace has an option AutoRegisterUnknown that is true by default. I highly advise you to turn it off. If you can't, there's ExcludeTypeFromAutoRegistration to opt-out for specific types.
@jods4 We actually depend on AutoRegisterUnknown, this app also targets net48 with Unity, which had that feature. Over the years we've added quite a bit of code that depends on it. But it sounds like ExcludeTypeFromAutoRegistration will clean this up.
@ipjohnson congrats on the new job and thank you for all the time you've put into Grace!