Singularity icon indicating copy to clipboard operation
Singularity copied to clipboard

GetInstance<T>() should return non-nullable T

Open grandsilence opened this issue 5 years ago • 2 comments

Describe the bug Method GetInstance<T?>() may return nullable type but it never be happen because exception will be thrown if unable to resolve it.

To Reproduce Screen-573

Expected behavior Method GetInstance<T> should accept T as generic parameter and return T type without nullable.
MethodGetInstanceOrDefault<T?>may accept T? as generic parameter and return T? with nullable type (return null if it's not resolved).

grandsilence avatar Nov 01 '20 14:11 grandsilence

It is currently actually possible to get a null reference here if you register the service with a custom expression that returns a null.

I think Singularity could handle this case better though by being more null aware. Most of the code was written before nullable references were a thing.

Rick-van-Dam avatar Nov 06 '20 12:11 Rick-van-Dam

My current solution is just an extension method. Anyway, thank you, you have a wonderful tool.

grandsilence avatar Nov 06 '20 13:11 grandsilence