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