Skip to content

Commands: Flow info into IDbContextFactory #5615

Closed

Description

@bricelam

There are two pieces of information that should somehow be flowed into IDbContextFactory so that users can properly implement it in a way that works well with the commands:

  • Environment
  • Startup project directory

Activity

  1. divega commented on Jun 2, 2016

    @divega
    Contributor

    Would these be flown through constructor parameters? Otherwise if we think our understanding of the requirements is going to evolve in the next few months (i.e. if the interface needs to change), should we more aggressively move stuff like this to our tooling packages before we RTM our runtime?

  2. bricelam commented on Jun 2, 2016

    @bricelam
    ContributorAuthor

    We talked about just adding a dictionary (overload?) to the Create method that could grow over time as needed.

  3. divega commented on Jun 2, 2016

    @divega
    Contributor

    I guess that works. It doesn't make it easy to discover what arguments the implementation should handle though. Would an options class work?

  4. added this to the 1.0.0 milestone on Jun 6, 2016
  5. bricelam commented on Jun 6, 2016

    @bricelam
    ContributorAuthor

    I like the idea of using an options class. That way it could be inject into other places in the future.

  6. jammerware commented on Jun 30, 2016

    @jammerware

    This change has caused us to wonder if maybe we've been using IDbContextFactory incorrectly.

    We have a custom context factory that implements IDbContextFactory<OurContext> that we inject into classes that need database access (repositories, for example). Then, when we need a context, we just create one from the factory:

    using(var context = contextFactory.Create()) {
        // do databasey stuff here
    }
    

    Since the interface no longer enforces a parameterless Create method, our code broke with RTM. Should we be registering a DbContextFactoryOptions object with our IoC container? Are we managing our context factory incorrectly?

  7. rowanmiller commented on Jun 30, 2016

    @rowanmiller
    Contributor

    @jammerware IDbContextFactory<OurContext> is designed to be a brute force way to tell EF Tooling (and other design time things) how to create your context without using DI etc. It's not really designed to be registered in DI and used at runtime. Of course, you can reuse it for that, but it probably makes more sense to define your own factory.

  8. jammerware commented on Jun 30, 2016

    @jammerware

    @rowanmiller Understood. Thanks for the clarification!

  9. 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

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions