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

  • SEARCH
  • Home
  • 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 7435015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:59:25+00:00 2026-05-29T09:59:25+00:00

The title describes my problem. E.g. public class EntryDAOModule extends AbstractModule { @Override protected

  • 0

The title describes my problem.

E.g.

public class EntryDAOModule extends AbstractModule {

    @Override
    protected void configure() {
        bind(EntryDAO.class).to(EntryDTOMongoImpl.class); // what should this be?       
    }
}

As shown, what should be the parameter to .to, given the below:

public class GenericDAOMongoImpl<T, K extends Serializable> extends BasicDAO<T, K> {
    public GenericDAOMongoImpl(Class<T> entityClass) throws UnknownHostException {
        super(entityClass, ConnectionManager.getDataStore());
    }
}

public class EntryDAOMongoImpl extends GenericDAOMongoImpl<EntryDTOMongoImpl, ObjectId> implements EntryDAO<EntryDTOMongoImpl> {
    private static final Logger logger = Logger.getLogger(EntryDAOMongoImpl.class);

    @Inject
    public EntryDAOMongoImpl(Class<EntryDTOMongoImpl> entityClass) throws UnknownHostException {
        super(entityClass);
    }
    ...
}

How can I instantiate the EntryDAOMongoImpl class like so:

Injector injector = Guice.createInjector(new EntryDAOModule());
this.entryDAO = injector.getInstance(EntryDAO.class); // what should this be?
  • 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-05-29T09:59:26+00:00Added an answer on May 29, 2026 at 9:59 am

    What you are going to need here is to create a factory. Using assisted injection can help you here.

    You can see my previous post regarding assisted injection

    but here’s the exact solution for your case:

    EntryDAOMongoImpl:

    public class EntryDAOMongoImpl extends GenericDAOMongoImpl<EntryDTOMongoImpl, ObjectId> implements EntryDAO<EntryDTOMongoImpl> {
        private static final Logger logger = Logger.getLogger(EntryDAOMongoImpl.class);
    
        @Inject
        public EntryDAOMongoImpl(@Assisted Class<EntryDTOMongoImpl> entityClass) throws UnknownHostException {
            super(entityClass);
        }
        ...
    }
    

    Factory:

    public interface EntryDAOFactory {
        public EntryDAOMongoImpl buildEntryDAO(Class<EntryDTOMongoImpl> entityClass);
    }
    

    Module:

    public class EntryDAOModule extends AbstractModule {
    
        @Override
        protected void configure() {
            //bind(EntryDAO.class).to(EntryDAOMongoImpl.class); // what should this be?
    
            FactoryModuleBuilder factoryModuleBuilder = new FactoryModuleBuilder();
            install(factoryModuleBuilder.build(EntryDAOFactory.class));
        }
    }
    

    Usage:

    Injector injector = Guice.createInjector(new EntryDAOModule());
    EntryDAOFactory factory = injector.getInstance(EntryDAOFactory.class);
    this.entryDAO = factory.buildEntryDAO(entityClass);
    

    If you are going to be using the EntryDAOMongoImpl as a singelton (natural usage of a singleton imo) then you can do the following without assisted injection within your module:

    public class EntryDAOModule extends AbstractModule {
    
        @Override
        protected void configure() {
            EtnryDTOMongoImpl dto = new EntryDTOMongoImpl(TargetEntry.class); //guessing here
            bind(EntryDAO.class).toInstance(new EntryDAOMongoImpl(dto)); // singleton   
        }
    }
    

    Let me know if that helps

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

Sidebar

Related Questions

Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
I'm not sure the title adequately describes the problem I've found myself with... Basically,
My title describes my problem... Can't do anything to solve it. It is a
The title doesn't actually fully describes the problem, that is: I have a table
The following test case describes my problem. CREATE TABLE the_table (id INT, Title CHAR(10));
The title describes my problem quite well. The offending line of code: connect(table, SIGNAL(cellChanged(row,
Well the title pretty well describes my problem. Here is a little bit more
sorry for the bad title, I don't know how to describe my problem. I
I am trying set up databinding as described in the title. The problem I
As the title describes, what are the different doctypes available and what do they

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.