Skip to content

Support DI for contructors of POCO #3342

Open

Description

@Artur2

Hello EF Development team.
I have a question about dependency injection.
Does EF looking for dependencies when materializing object from database in this manner ?

public class Person 
{

   public Person(DataContext context)
   {
    ....
   }

   // or maybe like this
   [Dependency]
   public DataContext Context {get;set;}
}

After loading and materializing from database DataContext(DataContext is inherited from DbContext) must injected in constructor.

Anything like this is possible now ?

Activity

  1. Artur2 commented on Oct 8, 2015

    @Artur2
    Author
  2. divega commented on Oct 8, 2015

    @divega
    Contributor

    We currently don't support this, but it is one of the capabilities for flexible object mapping (#240) we will consider adding in the future.

  3. Artur2 commented on Oct 8, 2015

    @Artur2
    Author

    @divega thank you for answer =)

  4. rowanmiller commented on Oct 9, 2015

    @rowanmiller
    Contributor

    This work is covered by #240

  5. divega commented on Jun 3, 2017

    @divega
    Contributor

    Reopening to prioritize separately from the main flexible mapping issue.

  6. reopened this on Jun 3, 2017
  7. added this to the Backlog milestone on Jun 3, 2017
  8. max-arshinov commented on May 28, 2019

    @max-arshinov

    Hi guys. What is the status of this issue? It looks that according to the roadmap (https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/features) it will not be implemented in EF Core 3.0. Will it?

  9. bricelam commented on May 28, 2019

    @bricelam
    Contributor

    Some support for constructor injection was added in 2.1.

  10. smitpatel commented on Nov 13, 2019

    @smitpatel
    Contributor

    @ajcvickers - What is pending in this issue? Should we track it differently?

  11. ajcvickers commented on Nov 14, 2019

    @ajcvickers
    Contributor

    @bricelam @smitpatel This is actually about being able to inject services registered in the application D.I. container. We haven't implemented this yet.

  12. AndriySvyryd commented on Sep 21, 2021

    @AndriySvyryd
    Member

    Related to #13540

  13. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions