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

Correctness: Make some private & internal classes sealed where possible #2559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions perf/benchmarkapps/Shared/BenchmarkServiceImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Grpc.Core;
using Grpc.Testing;

class BenchmarkServiceImpl : BenchmarkService.BenchmarkServiceBase
sealed class BenchmarkServiceImpl : BenchmarkService.BenchmarkServiceBase
{
#if CLIENT_CERTIFICATE_AUTHENTICATION
[Microsoft.AspNetCore.Authorization.Authorize]
Expand Down Expand Up @@ -98,4 +98,4 @@ public static SimpleResponse CreateResponse(SimpleRequest request)
var payload = new Payload { Body = body };
return new SimpleResponse { Payload = payload };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class ClientStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal sealed class ClientStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class DuplexStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal sealed class DuplexStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class ServerStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal sealed class ServerStreamingServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Grpc.AspNetCore.Server.Internal.CallHandlers;

internal class UnaryServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
internal sealed class UnaryServerCallHandler<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService, TRequest, TResponse> : ServerCallHandlerBase<TService, TRequest, TResponse>
where TRequest : class
where TResponse : class
where TService : class
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Server/Internal/GrpcMarkerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace Grpc.AspNetCore.Server.Internal;
/// A marker class used to determine if all the required gRPC services were added
/// to the <see cref="IServiceCollection"/>.
/// </summary>
internal class GrpcMarkerService
internal sealed class GrpcMarkerService
{
}
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Server/Internal/GrpcServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Grpc.AspNetCore.Server.Internal;

internal class GrpcServerBuilder : IGrpcServerBuilder
internal sealed class GrpcServerBuilder : IGrpcServerBuilder
{
public IServiceCollection Services { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Grpc.AspNetCore.Server.Internal;

internal class GrpcServiceOptionsSetup : IConfigureOptions<GrpcServiceOptions>
internal sealed class GrpcServiceOptionsSetup : IConfigureOptions<GrpcServiceOptions>
{
// Default to no send limit and 4mb receive limit.
// Matches the gRPC C impl defaults
Expand All @@ -45,7 +45,7 @@ public void Configure(GrpcServiceOptions options)
}
}

internal class GrpcServiceOptionsSetup<TService> : IConfigureOptions<GrpcServiceOptions<TService>> where TService : class
internal sealed class GrpcServiceOptionsSetup<TService> : IConfigureOptions<GrpcServiceOptions<TService>> where TService : class
{
private readonly GrpcServiceOptions _options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Grpc.AspNetCore.Server.Internal;

[DebuggerDisplay("{DebuggerToString(),nq}")]
[DebuggerTypeProxy(typeof(HttpContextStreamReader<>.HttpContextStreamReaderDebugView))]
internal class HttpContextStreamReader<TRequest> : IAsyncStreamReader<TRequest> where TRequest : class
internal sealed class HttpContextStreamReader<TRequest> : IAsyncStreamReader<TRequest> where TRequest : class
{
private readonly HttpContextServerCallContext _serverCallContext;
private readonly Func<DeserializationContext, TRequest> _deserializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Grpc.AspNetCore.Server.Internal;

[DebuggerDisplay("{DebuggerToString(),nq}")]
[DebuggerTypeProxy(typeof(HttpContextStreamWriter<>.HttpContextStreamWriterDebugView))]
internal class HttpContextStreamWriter<TResponse> : IServerStreamWriter<TResponse>
internal sealed class HttpContextStreamWriter<TResponse> : IServerStreamWriter<TResponse>
where TResponse : class
{
private readonly HttpContextServerCallContext _context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Grpc.AspNetCore.Server.Internal;

// Potentially remove in the future when https://github.com/dotnet/corefx/issues/31804 is implemented
internal class ReadOnlySequenceStream : Stream
internal sealed class ReadOnlySequenceStream : Stream
{
private static readonly Task<int> TaskOfZero = Task.FromResult(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Grpc.AspNetCore.Server.Internal;
/// <summary>
/// Creates server call handlers. Provides a place to get services that call handlers will use.
/// </summary>
internal partial class ServerCallHandlerFactory<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> where TService : class
internal sealed partial class ServerCallHandlerFactory<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> where TService : class
{
private readonly ILoggerFactory _loggerFactory;
private readonly IGrpcServiceActivator<TService> _serviceActivator;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Server/Internal/SystemClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Grpc.AspNetCore.Server.Internal;

internal class SystemClock : ISystemClock
internal sealed class SystemClock : ISystemClock
{
public static readonly SystemClock Instance = new SystemClock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Grpc.AspNetCore.Server.Model.Internal;

internal class BinderServiceMethodProvider<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> : IServiceMethodProvider<TService> where TService : class
internal sealed class BinderServiceMethodProvider<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> : IServiceMethodProvider<TService> where TService : class
{
private readonly ILogger<BinderServiceMethodProvider<TService>> _logger;

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Server/Model/Internal/MethodModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Grpc.AspNetCore.Server.Model.Internal;

internal class MethodModel
internal sealed class MethodModel
{
public MethodModel(IMethod method, RoutePattern pattern, IList<object> metadata, RequestDelegate requestDelegate)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace Grpc.AspNetCore.Server.Model.Internal;

internal class ProviderServiceBinder<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> : ServiceBinderBase where TService : class
internal sealed class ProviderServiceBinder<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> : ServiceBinderBase where TService : class
{
private readonly ServiceMethodProviderContext<TService> _context;
private readonly Type _declaringType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Grpc.AspNetCore.Server.Model.Internal;
/// <summary>
/// A registry of all the service methods in the application.
/// </summary>
internal class ServiceMethodsRegistry
internal sealed class ServiceMethodsRegistry
{
public List<MethodModel> Methods { get; } = new List<MethodModel>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Grpc.AspNetCore.Server.Model.Internal;

internal class ServiceRouteBuilder<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> where TService : class
internal sealed class ServiceRouteBuilder<[DynamicallyAccessedMembers(GrpcProtocolConstants.ServiceAccessibility)] TService> where TService : class
{
private readonly IEnumerable<IServiceMethodProvider<TService>> _serviceMethodProviders;
private readonly ServerCallHandlerFactory<TService> _serverCallHandlerFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Web/Internal/Base64PipeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Grpc.AspNetCore.Web.Internal;
/// <summary>
/// Reads and decodes base64 encoded bytes from the inner reader.
/// </summary>
internal class Base64PipeReader : PipeReader
internal sealed class Base64PipeReader : PipeReader
{
private readonly PipeReader _inner;
private ReadOnlySequence<byte> _currentDecodedBuffer;
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.AspNetCore.Web/Internal/Base64PipeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Grpc.AspNetCore.Web.Internal;
/// <summary>
/// Writes bytes as base64 encoded to the inner writer.
/// </summary>
internal class Base64PipeWriter : PipeWriter
internal sealed class Base64PipeWriter : PipeWriter
{
private readonly PipeWriter _inner;
// We have to write original data to buffer. GetSpan/GetMemory isn't guaranteed to return the
Expand Down Expand Up @@ -187,4 +187,4 @@ private void WriteRemainder()
_remainder = 0;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Web/Internal/GrpcWebFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Grpc.AspNetCore.Web.Internal;

internal class GrpcWebFeature :
internal sealed class GrpcWebFeature :
IRequestBodyPipeFeature,
IHttpResponseBodyFeature,
IHttpResponseTrailersFeature,
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Web/Internal/MemorySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Grpc.AspNetCore.Web.Internal;

internal class MemorySegment<T> : ReadOnlySequenceSegment<T>
internal sealed class MemorySegment<T> : ReadOnlySequenceSegment<T>
{
public MemorySegment(ReadOnlyMemory<T> memory)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Core.Api/CallCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static CallCredentials FromInterceptor(AsyncAuthInterceptor interceptor)
/// </summary>
public abstract void InternalPopulateConfiguration(CallCredentialsConfiguratorBase configurator, object? state);

private class CompositeCallCredentials : CallCredentials
private sealed class CompositeCallCredentials : CallCredentials
{
readonly IReadOnlyList<CallCredentials> credentials;

Expand All @@ -69,7 +69,7 @@ public override void InternalPopulateConfiguration(CallCredentialsConfiguratorBa
}
}

private class AsyncAuthInterceptorCredentials : CallCredentials
private sealed class AsyncAuthInterceptorCredentials : CallCredentials
{
readonly AsyncAuthInterceptor interceptor;

Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Core.Api/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ public ClientBaseDebugType(ClientBase client)
/// <summary>
/// Represents configuration of ClientBase. The class itself is visible to
/// subclasses, but contents are marked as internal to make the instances opaque.
/// The verbose name of this class was chosen to make name clash in generated code
/// The verbose name of this class was chosen to make name clash in generated code
/// less likely.
/// </summary>
protected internal class ClientBaseConfiguration
{
private class ClientBaseConfigurationInterceptor : Interceptor
private sealed class ClientBaseConfigurationInterceptor : Interceptor
{
readonly Func<IMethod, string?, CallOptions, ClientBaseConfigurationInfo> interceptor;

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Core.Api/Interceptors/CallInvokerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static CallInvoker Intercept(this CallInvoker invoker, Func<Metadata, Met
return new InterceptingCallInvoker(invoker, new MetadataInterceptor(interceptor));
}

private class MetadataInterceptor : Interceptor
private sealed class MetadataInterceptor : Interceptor
{
readonly Func<Metadata, Metadata> interceptor;

Expand Down
3 changes: 1 addition & 2 deletions src/Grpc.Core.Api/Interceptors/InterceptingCallInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#endregion

using System;
using System.Diagnostics;
using Grpc.Core.Utils;

Expand All @@ -27,7 +26,7 @@ namespace Grpc.Core.Interceptors;
/// intercept calls through a given interceptor.
/// </summary>
[DebuggerDisplay("{invoker}")]
internal class InterceptingCallInvoker : CallInvoker
internal sealed class InterceptingCallInvoker : CallInvoker
{
readonly CallInvoker invoker;
readonly Interceptor interceptor;
Expand Down
5 changes: 1 addition & 4 deletions src/Grpc.Core.Api/Internal/UnimplementedCallInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
#endregion

using System;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Utils;

namespace Grpc.Core.Internal;

/// <summary>
/// Call invoker that throws <c>NotImplementedException</c> for all requests.
/// </summary>
internal class UnimplementedCallInvoker : CallInvoker
internal sealed class UnimplementedCallInvoker : CallInvoker
{
public UnimplementedCallInvoker()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/Base64RequestStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Grpc.Net.Client.Web.Internal;

internal class Base64RequestStream : Stream
internal sealed class Base64RequestStream : Stream
{
private readonly Stream _inner;
private byte[]? _buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/Base64ResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Grpc.Net.Client.Web.Internal;

internal class Base64ResponseStream : Stream
internal sealed class Base64ResponseStream : Stream
{
private readonly Stream _inner;

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/GrpcWebRequestContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Grpc.Net.Client.Web.Internal;

internal class GrpcWebRequestContent : HttpContent
internal sealed class GrpcWebRequestContent : HttpContent
{
private readonly HttpContent _inner;
private readonly GrpcWebMode _mode;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/GrpcWebResponseContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Grpc.Net.Client.Web.Internal;

internal class GrpcWebResponseContent : HttpContent
internal sealed class GrpcWebResponseContent : HttpContent
{
private readonly HttpContent _inner;
private readonly GrpcWebMode _mode;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/GrpcWebResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Grpc.Net.Client.Web.Internal;
/// for trailers. When the trailers message is encountered then they are parsed as HTTP/1.1 trailers and
/// added to the HttpResponseMessage.TrailingHeaders.
/// </summary>
internal class GrpcWebResponseStream : Stream
internal sealed class GrpcWebResponseStream : Stream
{
private const int HeaderLength = 5;

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client.Web/Internal/OperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal interface IOperatingSystem
bool IsBrowser { get; }
}

internal class OperatingSystem : IOperatingSystem
internal sealed class OperatingSystem : IOperatingSystem
{
public static readonly OperatingSystem Instance = new OperatingSystem();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Grpc.Net.Client.Balancer.Internal;

internal class BalancerAddressEqualityComparer : IEqualityComparer<BalancerAddress>
internal sealed class BalancerAddressEqualityComparer : IEqualityComparer<BalancerAddress>
{
internal static readonly BalancerAddressEqualityComparer Instance = new BalancerAddressEqualityComparer();

Expand Down
9 changes: 2 additions & 7 deletions src/Grpc.Net.Client/Balancer/Internal/BalancerHttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
#endregion

#if SUPPORT_LOAD_BALANCING
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Shared;
using Microsoft.Extensions.Logging;

namespace Grpc.Net.Client.Balancer.Internal;

internal partial class BalancerHttpHandler : DelegatingHandler
internal sealed partial class BalancerHttpHandler : DelegatingHandler
{
private static readonly object SetupLock = new object();

Expand Down Expand Up @@ -178,7 +173,7 @@ internal static partial class Log
public static partial void SendingRequest(ILogger logger, Uri requestUri);

[LoggerMessage(Level = LogLevel.Trace, EventId = 2, EventName = "StartingConnectCallback", Message = "Starting connect callback for {Endpoint}.")]
private static partial void StartingConnectCallback(ILogger logger, string endpoint);
private static partial void StartingConnectCallback(ILogger logger, string endpoint);

public static void StartingConnectCallback(ILogger logger, DnsEndPoint endpoint)
{
Expand Down
Loading