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

Clean up some DI code #54732

Merged
merged 1 commit into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ protected override object VisitServiceProvider(ServiceProviderCallSite servicePr
return null;
}

protected override object VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, CallSiteFormatterContext argument)
{
return null;
}

protected override object VisitIEnumerable(IEnumerableCallSite enumerableCallSite, CallSiteFormatterContext argument)
{
argument.WriteProperty("itemType", enumerableCallSite.ItemType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ internal enum CallSiteKind

Transient,

CreateInstance,

ServiceScopeFactory,

Singleton
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ private CallSiteRuntimeResolver()

public object Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
{
// Fast path to avoid virtual calls if we already have the cached value in the root scope
if (scope.IsRootScope && callSite.Value is object cached)
{
return cached;
}

return VisitCallSite(callSite, new RuntimeResolverContext
{
Scope = scope
Expand Down Expand Up @@ -153,11 +159,6 @@ protected override object VisitServiceProvider(ServiceProviderCallSite servicePr
return context.Scope;
}

protected override object VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, RuntimeResolverContext context)
{
return serviceScopeFactoryCallSite.Value;
}

protected override object VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
{
var array = Array.CreateInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected override Type VisitRootCache(ServiceCallSite singletonCallSite, CallSi
protected override Type VisitScopeCache(ServiceCallSite scopedCallSite, CallSiteValidatorState state)
{
// We are fine with having ServiceScopeService requested by singletons
if (scopedCallSite is ServiceScopeFactoryCallSite)
pakrym marked this conversation as resolved.
Show resolved Hide resolved
if (scopedCallSite.ServiceType == typeof(IServiceScopeFactory))
{
return null;
}
Expand All @@ -100,8 +100,6 @@ protected override Type VisitScopeCache(ServiceCallSite scopedCallSite, CallSite

protected override Type VisitServiceProvider(ServiceProviderCallSite serviceProviderCallSite, CallSiteValidatorState state) => null;

protected override Type VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, CallSiteValidatorState state) => null;

protected override Type VisitFactory(FactoryCallSite factoryCallSite, CallSiteValidatorState state) => null;

internal struct CallSiteValidatorState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

namespace Microsoft.Extensions.DependencyInjection.ServiceLookup
{
Expand Down Expand Up @@ -51,8 +50,6 @@ protected virtual TResult VisitCallSiteMain(ServiceCallSite callSite, TArgument
return VisitConstant((ConstantCallSite)callSite, argument);
case CallSiteKind.ServiceProvider:
return VisitServiceProvider((ServiceProviderCallSite)callSite, argument);
case CallSiteKind.ServiceScopeFactory:
return VisitServiceScopeFactory((ServiceScopeFactoryCallSite)callSite, argument);
default:
throw new NotSupportedException(SR.Format(SR.CallSiteTypeNotSupported, callSite.GetType()));
}
Expand Down Expand Up @@ -84,8 +81,6 @@ protected virtual TResult VisitScopeCache(ServiceCallSite callSite, TArgument ar

protected abstract TResult VisitServiceProvider(ServiceProviderCallSite serviceProviderCallSite, TArgument argument);

protected abstract TResult VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, TArgument argument);

protected abstract TResult VisitIEnumerable(IEnumerableCallSite enumerableCallSite, TArgument argument);

protected abstract TResult VisitFactory(FactoryCallSite factoryCallSite, TArgument argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ConstantCallSite(Type serviceType, object defaultValue): base(ResultCache
Value = defaultValue;
}

public override Type ServiceType => DefaultValue?.GetType() ?? _serviceType;
public override Type ServiceType => _serviceType;
public override Type ImplementationType => DefaultValue?.GetType() ?? _serviceType;
public override CallSiteKind Kind { get; } = CallSiteKind.Constant;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ protected override Expression VisitServiceProvider(ServiceProviderCallSite servi
return ScopeParameter;
}

protected override Expression VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, object context)
{
return Expression.Constant(serviceScopeFactoryCallSite.Value);
}

protected override Expression VisitFactory(FactoryCallSite factoryCallSite, object context)
{
return Expression.Invoke(Expression.Constant(factoryCallSite.Factory), ScopeParameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ protected override object VisitServiceProvider(ServiceProviderCallSite servicePr
return null;
}

protected override object VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, ILEmitResolverBuilderContext argument)
{
AddConstant(argument, serviceScopeFactoryCallSite.Value);
return null;
}

protected override object VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ILEmitResolverBuilderContext argument)
{
if (enumerableCallSite.ServiceCallSites.Length == 0)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal ServiceProvider(IEnumerable<ServiceDescriptor> serviceDescriptors, Serv
// The list of built in services that aren't part of the list of service descriptors
// keep this in sync with CallSiteFactory.IsService
CallSiteFactory.Add(typeof(IServiceProvider), new ServiceProviderCallSite());
CallSiteFactory.Add(typeof(IServiceScopeFactory), new ServiceScopeFactoryCallSite(Root));
CallSiteFactory.Add(typeof(IServiceScopeFactory), new ConstantCallSite(typeof(IServiceScopeFactory), Root));
CallSiteFactory.Add(typeof(IServiceProviderIsService), new ConstantCallSite(typeof(IServiceProviderIsService), CallSiteFactory));

if (options.ValidateScopes)
Expand Down