Skip to content
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

CallSiteRuntimeResolver. VisitFactory method implements adding IsInstanceOfType check #79232

Closed
wants to merge 1 commit into from

Conversation

AlexKuai
Copy link

@AlexKuai AlexKuai commented Dec 5, 2022

var provider = new ServiceCollection()
    .AddSingleton(typeof(IHostedService), provider => new StringWriter())
    .BuildServiceProvider();
var hostedService = provider.GetService(typeof(IHostedService));

Using the above code, you will get an instance without any inheritance or implementation relationship.
I think we should throw an exception instead of getting an instance, which may cause problems in some cases.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 5, 2022
@ghost
Copy link

ghost commented Dec 5, 2022

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details
var provider = new ServiceCollection()
    .AddSingleton(typeof(IHostedService), provider => new StringWriter())
    .BuildServiceProvider();
var hostedService = provider.GetService(typeof(IHostedService));

Using the above code, you will get an instance without any inheritance or implementation relationship.
I think we should throw an exception instead of getting an instance, which may cause problems in some cases.

Author: AlexKuai
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@davidfowl
Copy link
Member

davidfowl commented Dec 5, 2022

What is this fixing? Where is the issue and the unit test? Does this regress the performance in anyway?

@buyaa-n buyaa-n added the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 7, 2022
@ghost ghost added the no-recent-activity label Dec 21, 2022
@ghost
Copy link

ghost commented Dec 21, 2022

This pull request has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Jan 5, 2023

This pull request will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the pull request, but please note that it will be locked if it remains inactive for another 30 days.

@ghost ghost closed this Jan 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 4, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-DependencyInjection community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants