Rich Newman

ComplexMovieListerFactory Class – Guice Java

package moviefindertest.guice;

import java.util.ArrayList;
import java.util.List;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provider;

public class ComplexMovieListerFactory implements Provider<MovieLister> {
      
      private Injector injector;
      
      @Inject
      public ComplexMovieListerFactory(Injector injector) {
            this.injector = injector;
      }
      
      @Override
      public MovieLister get()
      {
            Movie andreiRublevMovie = injector.getInstance(Key.get(Movie.class, AndreiRublev.class));
            Movie sacrificeMovie = injector.getInstance(Movie.class);
            List<Movie> movies = new ArrayList<Movie>();
            movies.add(andreiRublevMovie);
            movies.add(sacrificeMovie);
            ComplexMovieFinder complexMovieFinder = new ComplexMovieFinder();
            complexMovieFinder.setMovies(movies);
            MovieLister complexMovieLister = new MovieLister(complexMovieFinder);
            return complexMovieLister;
            
      }
}

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: