コード例 #1
0
        protected virtual DbContextOptions <TDbContext> CreateOptions <TDbContext>(string connectionString, DbConnection existingConnection) where TDbContext : DbContext
        {
            if (_iocResolver.IsRegistered <IPlusDbContextConfigurer <TDbContext> >())
            {
                var configuration = new PlusDbContextConfiguration <TDbContext>(connectionString, existingConnection);
                ReplaceServices(configuration);

                using (var configurer = _iocResolver.ResolveAsDisposable <IPlusDbContextConfigurer <TDbContext> >())
                {
                    configurer.Object.Configure(configuration);
                }

                return(configuration.DbContextOptions.Options);
            }

            if (_iocResolver.IsRegistered <DbContextOptions <TDbContext> >())
            {
                return(_iocResolver.Resolve <DbContextOptions <TDbContext> >());
            }

            throw new PlusException($"Could not resolve DbContextOptions for {typeof(TDbContext).AssemblyQualifiedName}.");
        }
コード例 #2
0
 protected virtual void ReplaceServices <TDbContext>(PlusDbContextConfiguration <TDbContext> configuration) where TDbContext : DbContext
 {
     configuration.DbContextOptions.ReplaceService <IEntityMaterializerSource, PlusEntityMaterializerSource>();
 }