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 7957295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:13:44+00:00 2026-06-04T04:13:44+00:00

I need to have lazyload logic for creating mappers in my class. Each mapper

  • 0

I need to have lazyload logic for creating mappers in my class. Each mapper Inherited from Mapper<T> interface. But through the time object working it could use multiple mappers depending from input it handling.

As I see it’s not a good way to inject injector in class, but how could I implement lazyload do not doing that? I cant use Provider<Mapper> because provider have no options to determine which exact mapper I need at time.

Thanks a lot.

  • 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-04T04:13:45+00:00Added an answer on June 4, 2026 at 4:13 am

    This may not be the best solution, but it could work for you.

    You can implement a Provider that allows you to supply the dynamic input. Then have that Provider injected into the classes that need them so you can create your the object you need dynamically.

    Here’s a snippet from the Provider JavaDoc:

    An implementation class may always choose to have a Provider instance injected, rather than having a T injected directly. This may give you access to multiple instances, instances you wish to safely mutate and discard, instances which are out of scope (e.g. using a @RequestScoped object from within a @SessionScoped object), or instances that will be initialized lazily.

    It could look something like the following. I personally think it’s fine to inject the Injector into a provider because it’s part of the injection framework. The goal is to keep the Injector out of your application code, and this certainly does.

    public class FooProvider implements Provider<Foo>
    
        @Inject
        private Injector injector;
    
        private String input;
    
        public void setInput(String input){
            this.input = input;
        }
    
        @Override
        public Foo get(){
            if(input.equals("bar")){
                injector.getInstance(Bar.class); // Bar implements Foo
            }
            else{
                injector.getInstance(Baz.class; // Baz implements Foo
            }
        }
    }
    

    Then elsewhere…

    public class Goo{
    
        @Inject
        Provider<Foo> fooProvider;
    
        public Foo goo(String input){
            fooProvider.setInput(input);
            return fooProvider.get();
        }
    }
    

    The key is to make sure each provider instance is unique per injection point, which I think it is by default. Since this provider has mutable state, you cannot have this being thrown around your application (and potentially doing the wrong thing in a multi-threaded environment) unless that is what you intend on it doing. Then you will need to take more precautions.

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

Sidebar

Related Questions

I have a need to have a multi-page html, with each page containing an
I have need to return multiple results from a subquery and have been unable
i have a site using jquery lazyload its working fine, but now i want
I have need for a LinkedBlockingQueue but what I am passing primitives to it.
I have need to store multiple values in list or array for a moment.
I have need to produce LINE, BAR, and PIE charts in Rails. I have
I have need to pack four signed bytes into 32-bit integral type. this is
I have need for a function pointer that takes two arguments and returns a
I have need for AutoCompliteTextView in PreferenceActivity so I extended DialogPreference. My auto-complite is
I need to have stored procedure where I can run multiple cursors. Loop over

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.