EF Core Defined in Library Assembly, Configured in ASPNET Asembly
Hey, I've been away from netcore for a while and im getting back into it. I have two assemblies right now:
* Journey.Web
* Journey.Application
I haven't decided to seperate much yet, just keeping the entrypoint seperate from the core logic. Thus most behavior is in the
Journey.Application
assembly.
I've started to set up some EF Core, I've created an ApplicationDbContext
in Journey.Application
and started building configurations for my entities using the IEntityTypeConfiguration<T>
pattern with the following in my Application Context:
This is my configuration for Account
:
Note that I have configured Account
has a key x.Id
and The context should be picking up this configuration via the assembly binding in OnModelCreating
.
However, when I run the following command from my solution:
I get the following error:
It does not seem like it's picking up the EntityTypeConfiguration
since it doesn't seem to pick up the .HasKey
definition. I also tried putting an exception in the Type Configuration method and it did not fail with my exception, so im relatively certain it's not executing my model binders, does anyone know what I've done wrong here?1 Reply
I'm guessing it's because I have a dependency, and the instantiation here is not happening in the DI Context? Thus it's not created, and this model is not configured.
It seems that way, after moving the deps to my context and instantiating the configuration in the
OnModelCreating
it works. Does anyone have a better way for allowing the EntityTypeConfiguration<T>
to work from the Service Collection?