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

Remove indirection in DependencyInjection #52140

Merged
merged 8 commits into from
May 26, 2021

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Apr 30, 2021

The ServiceProviderEngine is a pretty thick abstraction and most of it didn't serve a purpose and can be inlined into the service provider removing the ICallback interface with it.

Shrink it down to only the service accessor building logic.

Remove ScopeState as it was an extra allocation per scope.

# Conflicts:
#	src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteRuntimeResolver.cs
#	src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ServiceProviderEngine.cs
#	src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ServiceProviderEngineScope.cs
#	src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/CallSiteTests.cs
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Apr 30, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

The ServiceProviderEngine is a pretty thick abstraction and most of it didn't serve a purpose and can be inlined into the service provider removing the ICallback interface with it.

Author: pakrym
Assignees: -
Labels:

area-Extensions-DependencyInjection, new-api-needs-documentation

Milestone: -

{
Func<ServiceProviderEngineScope, object> realizedService = _expressionResolverBuilder.Build(callSite);
RealizedServices[callSite.ServiceType] = realizedService;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These calls were redundant.

@pakrym pakrym marked this pull request as ready for review May 4, 2021 15:36
@eerhardt
Copy link
Member

@pakrym - can you resolve the conflicts on this PR?

@pakrym
Copy link
Contributor Author

pakrym commented May 17, 2021

Will do, missed them.

…tion

# Conflicts:
#	src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ServiceProviderEngineScope.cs
#	src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceCollectionContainerBuilderTestExtensions.cs
@davidfowl
Copy link
Member

Lets get this for preview6

public RuntimeServiceProviderEngine(IEnumerable<ServiceDescriptor> serviceDescriptors) : base(serviceDescriptors)
{
}
public static RuntimeServiceProviderEngine Instance { get; } = new RuntimeServiceProviderEngine();
Copy link
Member

@davidfowl davidfowl May 20, 2021

Choose a reason for hiding this comment

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

I don't think we should do this, it isn't stateless right? I see it's stateless.

@@ -8,28 +8,30 @@

namespace Microsoft.Extensions.DependencyInjection.ServiceLookup
{
internal sealed class ServiceProviderEngineScope : IServiceScope, IServiceProvider, IAsyncDisposable
Copy link
Member

Choose a reason for hiding this comment

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

nit: let's rename this to ServiceProviderScope on a next PR

@davidfowl davidfowl merged commit ecdb90e into dotnet:main May 26, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 27, 2021
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.

4 participants