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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:00:00+00:00 2026-06-13T16:00:00+00:00

How can I inject dependencies into objects that weren’t created by a DI framework?

  • 0

How can I inject dependencies into objects that weren’t created by a DI framework?

I am running an application on Google App Engine using Objectify, so POJOs are created by Objectify when data is fetched from the datastore. Personally i like having convenience methods to get related objects, like car.getOwner().getName() The car object is created by Objectify. The code of getOwner() owner would be something like

public Person getOwner(){
    return PersonService.getById(this.ownerId);
}

I could improve it with a ServiceLocator

public Person getOwner(){
    return ServiceLocator.getService(PersonService.class).getById(this.ownerId);
}

But how would I do this with DI?

I looked at Guice, but i can only think of putting the Injector in a singleton and access it from the getOwner method.

Is my thinking flawed?

  • 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-13T16:00:02+00:00Added an answer on June 13, 2026 at 4:00 pm

    If you are using Objectify4 you can subclass ObjectifyFactory and override the construct() method. This will allow you to inject your entity classes.

    You can see an example here: https://github.com/stickfigure/motomapia/blob/master/java/com/motomapia/OfyFactory.java

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

Sidebar

Related Questions

I have a WPF UserControl that I'd like to inject dependencies into. What's the
I'm using Spring 3 and want to inject some dependencies into a class that
Is there any way we can inject new methods and properties into classes during
I wonder, if I can inject a list of (stateless) beans, that all implementing
Question: Is there a way to use Ninject to inject dependencies into my MVC
is there any way to inject dependencies into Doctrine2 models with Silex? Since the
Can anyone advice me how can I inject multiple dependencies for a same bean
In MVC 3, I understand you can create custom WebViewPages. Can you inject dependencies,
I'm looking for suggestions on how to inject runtime dependencies into JPA entities retrieved
Possible Duplicate: How can i inject dependencies to Symfony Console commands? I want to

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.