Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

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

Open
grandsilence opened this issue Nov 1, 2020 · 2 comments
Open

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

grandsilence opened this issue Nov 1, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@grandsilence
Copy link

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 grandsilence added the bug Something isn't working label Nov 1, 2020
@Barsonax
Copy link
Owner

Barsonax commented Nov 6, 2020

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.

@grandsilence
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants