-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Report warning when using the package without invoking AddServices #30
Labels
enhancement
New feature or request
Comments
kzu
added a commit
that referenced
this issue
Nov 10, 2022
Conditions for reporting the warning are: * Detect if users have access to IServiceCollection in the current project: it may be that they just added the package to get the [Service] attribute for a library. Nothing to do in that case. * Detect if users actually invoke IServiceCollection members in the current project, more or less flexibly (i.e. don't verify much where specifically, since the DI library can be used in multiple contexts). If they do, then it's an indication that there should be a call to the AddServices extension method too somewhere. As a hint, report the location on the first invocation to a service collection method (or extension method). * Report as a warning, since we can determine this wrong, depending on whether users are initializing services some other way or indirectly. This allows them to ignore the warning using the regular configuration mechanisms for analyzers and diagnostics. Closes #30
kzu
added a commit
that referenced
this issue
Nov 10, 2022
Conditions for reporting the warning are: * Detect if users have access to IServiceCollection in the current project: it may be that they just added the package to get the [Service] attribute for a library. Nothing to do in that case. * Detect if users actually invoke IServiceCollection members in the current project, more or less flexibly (i.e. don't verify much where specifically, since the DI library can be used in multiple contexts). If they do, then it's an indication that there should be a call to the AddServices extension method too somewhere. As a hint, report the location on the first invocation to a service collection method (or extension method). * Report as a warning, since we can determine this wrong, depending on whether users are initializing services some other way or indirectly. This allows them to ignore the warning using the regular configuration mechanisms for analyzers and diagnostics. Closes #30
kzu
added a commit
that referenced
this issue
Nov 10, 2022
Conditions for reporting the warning are: * Detect if users have access to IServiceCollection in the current project: it may be that they just added the package to get the [Service] attribute for a library. Nothing to do in that case. * Detect if users actually invoke IServiceCollection members in the current project, more or less flexibly (i.e. don't verify much where specifically, since the DI library can be used in multiple contexts). If they do, then it's an indication that there should be a call to the AddServices extension method too somewhere. As a hint, report the location on the first invocation to a service collection method (or extension method). * Report as a warning, since we can determine this wrong, depending on whether users are initializing services some other way or indirectly. This allows them to ignore the warning using the regular configuration mechanisms for analyzers and diagnostics. Closes #30
kzu
added a commit
that referenced
this issue
Nov 10, 2022
Conditions for reporting the warning are: * Detect if users have access to IServiceCollection in the current project: it may be that they just added the package to get the [Service] attribute for a library. Nothing to do in that case. * Detect if users actually invoke IServiceCollection members in the current project, more or less flexibly (i.e. don't verify much where specifically, since the DI library can be used in multiple contexts). If they do, then it's an indication that there should be a call to the AddServices extension method too somewhere. As a hint, report the location on the first invocation to a service collection method (or extension method). * Report as a warning, since we can determine this wrong, depending on whether users are initializing services some other way or indirectly. This allows them to ignore the warning using the regular configuration mechanisms for analyzers and diagnostics. Closes #30
kzu
added a commit
that referenced
this issue
Nov 10, 2022
Conditions for reporting the warning are: * Detect if users have access to IServiceCollection in the current project: it may be that they just added the package to get the [Service] attribute for a library. Nothing to do in that case. * Detect if users actually invoke IServiceCollection members in the current project, more or less flexibly (i.e. don't verify much where specifically, since the DI library can be used in multiple contexts). If they do, then it's an indication that there should be a call to the AddServices extension method too somewhere. As a hint, report the location on the first invocation to a service collection method (or extension method). * Report as a warning, since we can determine this wrong, depending on whether users are initializing services some other way or indirectly. This allows them to ignore the warning using the regular configuration mechanisms for analyzers and diagnostics. Closes #30
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This source generator is quite magical, but it still can't inject itself in the
service collection without users invoking the provided
ServiceCollection.AddServices()
extension method. This has tripped aa new user
in the past, which is not a great user experience.
We should make every attempt to detect this situation, so the idea is to:
IServiceCollection
in the current project: it may be thatthey just added the package to get the
[Service]
attribute for a library. Nothing to doin that case.
IServiceCollection
members in the current project, moreor less flexibly (i.e. don't verify much where specifically, since the DI library can be used
in multiple contexts). If they do, then it's an indication that there should be a call to the
AddServices
extension method too somewhere. As a hint, report the location on thefirst invocation to a service collection method (or extension method).
are initializing services some other way or indirectly. This allows them to ignore the warning
using the regular configuration mechanisms for analyzers and diagnostics.
The text was updated successfully, but these errors were encountered: