My project calls for a Core Application that acts as a central point for small app style applications to interact with a much larger central system. These are TV applications so don't think mobile. Most applications will be able to reference this core without needing any additional code. However, some of the applications (which are not known at this time) will most likely need to have additional functionality. I want to support this additional functionality with a Plug-in model that allows for extending the functionality of the Core without changing the Core. Since the source may not be available to the Plug-in developer. I want to use EF Code First to allow the plug-ins to extend the data model.
For example I might define a User entity and they may need to extend it to support CustomUser:User. I would like to build the table for this like:
modelBuilder.Entity<User>()
.Map(m => m.ToTable("User"))
.Map<CustomUser>(m => m.ToTable("CustomUser")); // Would like this portion provided by plug-in
I know this works if you do it all at once, but I don't see how to pull in my mapping from the plug-in . I have tried seperating it into two statements like:
Core
modelBuilder.Entity<User>()
.Map(m => m.ToTable("User"));
Plugin
modelBuilder.Entity<User>()
.Map<CustomUser>(m => m.ToTable("CustomUser"));
However, when this runs I get an error stating that the User entity must be defined in a single mapping statement.
So up until now I have been trying to figure out how to pass just the mapping info in from the Plug-in before I define my User entity, but don't see a way to pass it in at runtime since the Core project doesn't know about the Plug-ins "CustomUser".
If further clarification is needed please ask.
Edit 1: As a point of information. I followed this post here and can replicate its functionality, but it doesn't allow me to build the relationships that I'm after. Unless I'm missing something.
Edit 2: Doing additional research I found that I can build my mapping configuration as in this post, but I can't figure out how to pass my configuration in once created. I'm currently using MEF, but I'm open to trying a different method. I have heard that Ninject can do this sort of thing, but I'm not clear on how that works.