##EfModelComposer
Manually adding and maintaining EntityFramework type configurations can be a pain. K Scott Allen wrote a great blog post showing how to use MEF in order to add configurations in a scalable way. This library packages the provided approach into a pluggable way.
Install from Nuget
Install-Package EfModelComposer
Example Usage
class FooContext : DbContext
{
...
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.ComposeModelConfiguration(Assembly.GetExecutingAssembly());
base.OnModelCreating(modelBuilder);
}
...
}
class City
{
public int Id { get; set; }
public string Name { get; set; }
}
[ExportConfiguration]
class CityConfig : EntityConfiguration<City>
{
public CityConfig()
{
Property(c => c.Name).HasMaxLength(100);
}
}
Once your DbContext is configured to call the ComposeModelConfiguration extension method any exported EntityConfiguration (a derived type of EntityTypeConfiguration) will be automatically found and loaded when OnModelCreating is called.