1 #region Copyright notice and license 2 // Copyright 2019 The gRPC Authors 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 #endregion 16 17 using System; 18 using System.Diagnostics.CodeAnalysis; 19 20 namespace Grpc.Core 21 { 22 /// <summary> 23 /// Specifies the location of the service bind method for a gRPC service. 24 /// The bind method is typically generated code and is used to register a service's 25 /// methods with the server on startup. 26 /// 27 /// The bind method signature takes a <see cref="ServiceBinderBase"/> and an optional 28 /// instance of the service base class, e.g. <c>static void BindService(ServiceBinderBase, GreeterService)</c>. 29 /// </summary> 30 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 31 public class BindServiceMethodAttribute : Attribute 32 { 33 // grpc-dotnet uses reflection to find the bind service method. 34 // DynamicallyAccessedMembersAttribute instructs the linker to never trim the method. 35 private const DynamicallyAccessedMemberTypes ServiceBinderAccessibility = DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods; 36 37 /// <summary> 38 /// Initializes a new instance of the <see cref="BindServiceMethodAttribute"/> class. 39 /// </summary> 40 /// <param name="bindType">The type the service bind method is defined on.</param> 41 /// <param name="bindMethodName">The name of the service bind method.</param> BindServiceMethodAttribute([DynamicallyAccessedMembers(ServiceBinderAccessibility)] Type bindType, string bindMethodName)42 public BindServiceMethodAttribute([DynamicallyAccessedMembers(ServiceBinderAccessibility)] Type bindType, string bindMethodName) 43 { 44 BindType = bindType; 45 BindMethodName = bindMethodName; 46 } 47 48 /// <summary> 49 /// Gets the type the service bind method is defined on. 50 /// </summary> 51 [DynamicallyAccessedMembers(ServiceBinderAccessibility)] 52 public Type BindType { get; } 53 54 /// <summary> 55 /// Gets the name of the service bind method. 56 /// </summary> 57 public string BindMethodName { get; } 58 } 59 } 60