001package edu.pdx.cs410J.di; 002 003import com.google.inject.AbstractModule; 004import com.google.inject.Provides; 005import com.google.inject.Singleton; 006import com.google.inject.name.Names; 007 008import java.io.File; 009 010/** 011 * A Guice module that configures the well-known objects for the book store application 012 */ 013public class BookStoreModule extends AbstractModule 014{ 015 @Override 016 protected void configure() 017 { 018 bind(BookInventory.class).to(BookDatabase.class); 019 020 bind(CreditCardService.class).to(FirstBankOfPSU.class).in(Singleton.class); 021 022 bind(String.class).annotatedWith( Names.named("ServerHost") ).toInstance( "localhost" ); 023 bind(Integer.class).annotatedWith( Names.named("ServerPort") ).toInstance( 8080 ); 024 025// String tmpdir = System.getProperty("java.io.tmpdir"); 026// File directory = new File(tmpdir); 027// bind(File.class).annotatedWith(DataDirectory.class).toInstance(directory); 028 } 029 030 @Provides 031 @DataDirectory 032 protected File provideDataDirectory() { 033 String tmpdir = System.getProperty( "java.io.tmpdir" ); 034 return new File( tmpdir ); 035 } 036}