protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>([NotNull] string connectionString, [CanBeNull] DbConnection existingConnection) where TDbContext : DbContext { if (_iocResolver.IsRegistered <ICodeZeroDbContextConfigurer <TDbContext> >()) { var configuration = new CodeZeroDbContextConfiguration <TDbContext>(connectionString, existingConnection); ReplaceServices(configuration); using (var configurer = _iocResolver.ResolveAsDisposable <ICodeZeroDbContextConfigurer <TDbContext> >()) { configurer.Object.Configure(configuration); } return(configuration.DbContextOptions.Options); } if (_iocResolver.IsRegistered <DbContextOptions <TDbContext> >()) { return(_iocResolver.Resolve <DbContextOptions <TDbContext> >()); } throw new CodeZeroException($"Could not resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}."); }
protected virtual void ReplaceServices <TDbContext>(CodeZeroDbContextConfiguration <TDbContext> configuration) where TDbContext : DbContext { configuration.DbContextOptions.ReplaceService <IEntityMaterializerSource, CodeZeroEntityMaterializerSource>(); }