Skip to content

Unclear if it's possible to register in the DbContext's constructor or not #13

@cbp123

Description

@cbp123

Hi there,
We are using this package in EF6 and it's working well, but running into trouble with where to register hooks exactly.

The logical place is in the constructor of the DbContext, but that can run into trouble as the very first time you construct the DbContext, the model may not have been created yet. This is a problem for unit tests.

Registering in OnModelCreating doesn't work either though.

public class MyDbContext : DbContext { public MyDbContext() { this.OnSave().Attach(new MyHook()); // Fails the first time the context is constructed, as model has not been created yet. } }

Wondering what strategy you take for registering the hooks.
Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions