1 /* 2 * Copyright (C) 2016 The Dagger 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 */ 16 17 package dagger.grpc.server; 18 19 import java.lang.annotation.Documented; 20 import java.lang.annotation.ElementType; 21 import java.lang.annotation.Target; 22 23 /** 24 * Annotates a class that implements a gRPC service. 25 * 26 * <p>Generates several types when annotating a class {@code Foo}: 27 * 28 * <ul> 29 * <li>Interfaces {@code FooComponent} and {@code FooComponent.Factory}. 30 * <li>{@linkplain dagger.Module Modules} {@code FooGrpcProxyModule} and {@code 31 * FooGrpcServiceModule}. 32 * </ul> 33 * 34 * <p>To use these types to configure a server: 35 * 36 * <ol> 37 * <li>Create a {@linkplain dagger.Subcomponent subcomponent} that implements {@code FooComponent} 38 * and installs {@code FooGrpcServiceModule}. 39 * <li>Install {@link NettyServerModule} or another {@link ServerModule} subclass and {@code 40 * FooGrpcProxyModule} into your {@link javax.inject.Singleton @Singleton} {@linkplain 41 * dagger.Component component}. 42 * <li>Bind an implementation of {@code FooComponent.Factory} in your {@link 43 * javax.inject.Singleton @Singleton} {@linkplain dagger.Component component}. The 44 * implementation will typically inject the {@link javax.inject.Singleton @Singleton} 45 * {@linkplain dagger.Component component} and call subcomponent factory methods to instantiate 46 * the correct subcomponent. 47 * </ol> 48 */ 49 @Documented 50 @Target(ElementType.TYPE) 51 public @interface GrpcService { 52 /** The class that gRPC generates from the proto service definition. */ grpcClass()53 Class<?> grpcClass(); 54 } 55