Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:49:15+00:00 2026-06-12T06:49:15+00:00

I have setup a Filter for a specific set of requests i.e. */dispatch through

  • 0

I have setup a Filter for a specific set of requests i.e. */dispatch through my Guice Listener.

In this filter I want to change the binding for type BaseService (an interface containing one method ) in each request based on the Request URI. i.e. if the URI is /hello/dispatch I want BaseService to bind to HelloServiceImpl else if the URI is /bye/dispatch I want to bind to ByeServiceImpl . Both implement the BaseService .

Now somewhere in one my random class that participates in the servlet request handling I want to inject the appropriate implementation of BaseService specific to current request.

Is this possible ? How ? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:49:16+00:00Added an answer on June 12, 2026 at 6:49 am

    Consider using a factory pattern for providing different types of BaseService.

    public interface ServiceFactory
    {
      public BaseService create(String uri);
    }
    
    public class ServiceFactoryImpl implements ServiceFactory
    {
      @Override
      public BaseService create(String uri)
      {
        if(uri.equals("/hello/dispatch"))
          return new HelloServiceImpl();
    
        else if (uri.equals("/bye/dispatch"))
          return new ByeServiceImpl();
    
        return null;
      }
    }
    

    Then the factory in your module.

    bind(ServiceFactory.class).to(ServiceFactoryImpl.class);
    

    and inject this into the Request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Metafizzy's Isotope plugin and have it set up to filter using
i have setup a profanity filter with bad words in a XML file and
I have setup a postfix mail receiving server. On this I am using DKIM
The action filter I want to inject into starts like this public class UserAuthorisation
I have a multi-project setup for a game. There is a very specific sub
I want to open a specific type of file that my app can already
I have a checkstyle suppression filter setup (e.g. ignore magic numbers in unit test
Update : I have changed this question to be about the specific problem I
I have a filter setup that runs a function which checks if the user
I have setup airbrake in my app but it doesn't seem to log any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.