GameKit.DependencyInjection currently generates GetRequiredService<T>() for every constructor and factory dependency except IEnumerable<T>. Consequently, a nullable dependency still behaves as required.
For example, GraphicsPipelineBuilder accepts Window? because it can build pipelines with explicit texture formats in a windowless container. Window is only needed by AddColorFormatFromDisplay(). Its registration therefore needs an otherwise unnecessary provider factory solely to call GetService<Window>():
AddTransient<GraphicsPipelineBuilder>(static provider => new GraphicsPipelineBuilder(
provider.GetRequiredService<GpuDevice>(),
provider.GetService<Window>(),
provider.GetRequiredService<IShaderLoader>()));
The source generator should use nullable reference annotations when resolving generated constructor and factory arguments:
T and oblivious reference types: GetRequiredService<T>()
T?: GetService<T>()
IEnumerable<T>: retain the existing GetServices<T>() behavior
This should apply consistently to generated singleton and transient constructor injection, delegate factories, and instance factory methods.
Acceptance cases:
- An unregistered nullable dependency is passed as
null.
- A registered nullable dependency is resolved normally, including from the requesting child provider.
- An unregistered non-nullable dependency still throws.
GraphicsPipelineBuilder can be registered with AddTransient<GraphicsPipelineBuilder>() without making Window mandatory.
GameKit.DependencyInjection currently generates
GetRequiredService<T>()for every constructor and factory dependency exceptIEnumerable<T>. Consequently, a nullable dependency still behaves as required.For example,
GraphicsPipelineBuilderacceptsWindow?because it can build pipelines with explicit texture formats in a windowless container.Windowis only needed byAddColorFormatFromDisplay(). Its registration therefore needs an otherwise unnecessary provider factory solely to callGetService<Window>():The source generator should use nullable reference annotations when resolving generated constructor and factory arguments:
Tand oblivious reference types:GetRequiredService<T>()T?:GetService<T>()IEnumerable<T>: retain the existingGetServices<T>()behaviorThis should apply consistently to generated singleton and transient constructor injection, delegate factories, and instance factory methods.
Acceptance cases:
null.GraphicsPipelineBuildercan be registered withAddTransient<GraphicsPipelineBuilder>()without makingWindowmandatory.