Skip to content

Annotate Microsoft.Extensions.DependencyInjection.Abstractions for nu… #37488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 16, 2020

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Jun 5, 2020

…llable reference types

Contributes to #2339

@pranavkm pranavkm marked this pull request as ready for review June 5, 2020 16:54
@pranavkm
Copy link
Contributor Author

pranavkm commented Jun 5, 2020

cc: @buyaa-n, @stephentoub

@@ -5,13 +5,14 @@
using System;
using System.Reflection;

#nullable enable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: not a big deal, but we've generally been putting these above the using statements when they're needed

@@ -69,6 +71,7 @@ public static object GetRequiredService(this IServiceProvider provider, Type ser
/// <param name="provider">The <see cref="IServiceProvider"/> to retrieve the service object from.</param>
/// <returns>A service object of type <typeparamref name="T"/>.</returns>
/// <exception cref="System.InvalidOperationException">There is no service of type <typeparamref name="T"/>.</exception>
[return: NotNull]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to constrain T to be non-nullable?

public static T GetRequiredService<T>(this IServiceProvider provider) where T : notnull

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Other APIs, like the one below, could use that constraint as well.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfowl and I went over some of the other APIs here. We added the notnull constraint to another type, but the rest of these APIs don't qualify for additional constraints.

@pranavkm pranavkm requested a review from JamesNK June 10, 2020 15:51
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a shared source file. So you have to annotate it in case other projects that reference it haven't been updated to nullable.

@pranavkm
Copy link
Contributor Author

@stephentoub does this need to be API reviewed before this is merged?

@stephentoub
Copy link
Member

@pranavkm, thanks for checking, but nope. We plan to do an all-up .NET 5 annotations review en mass for all the annotations added in the release. cc: @terrajobst

@pranavkm pranavkm merged commit 025bf93 into dotnet:master Jun 16, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants