1 /* 2 * Copyright (C) 2018 The Android Open Source Project 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 package com.android.tradefed.guice; 17 18 import com.android.tradefed.config.IConfiguration; 19 20 import com.google.inject.AbstractModule; 21 22 /** 23 * Guice module that can be used anywhere in a TF invocation to requests the Guice-Tradefed 24 * supported objects. 25 */ 26 public class InvocationScopeModule extends AbstractModule { 27 28 private InvocationScope mScope; 29 30 public InvocationScopeModule() { 31 this(InvocationScope.getDefault()); 32 } 33 34 public InvocationScopeModule(InvocationScope scope) { 35 mScope = scope; 36 } 37 38 @Override 39 public void configure() { 40 // Tell Guice about the scope 41 bindScope(InvocationScoped.class, mScope); 42 43 // Make our scope instance injectable 44 bind(InvocationScope.class).toInstance(mScope); 45 46 // IConfiguration is a supported Guice-Tradefed object. 47 bind(IConfiguration.class) 48 .toProvider(InvocationScope.<IConfiguration>seededKeyProvider()) 49 .in(InvocationScoped.class); 50 } 51 } 52