public virtual IEnumerable <Type> GetContextTypes() => ContextTool.GetContextTypes(_assembly) .Concat( MigrationAssembly.GetMigrationTypes(_assembly) .Select(MigrationAssembly.TryGetContextType) .Where(t => t != null)) .Distinct();
public virtual Type GetContextType([CanBeNull] string name) { var contextType = ContextTool.SelectType(GetContextTypes(), name); _logger.Value.LogVerbose(Strings.LogUseContext(contextType.Name)); return(contextType); }
public virtual IEnumerable <Type> GetContextTypes() => ContextTool.GetContextTypes(_assembly) .Concat( _assembly.GetConstructibleTypes() .Where(t => typeof(Migration).IsAssignableFrom(t.AsType())) .Select(t => t.GetCustomAttribute <DbContextAttribute>()?.ContextType) .Where(t => t != null)) .Distinct();
protected virtual DbContext CreateContext(Type type, string startupAssemblyName) { var context = new ContextTool(_services).CreateContext(type, startupAssemblyName); var services = ((IAccessor <IServiceProvider>)context).Service; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); loggerFactory.AddProvider(_loggerProvider); return(context); }
protected virtual DbContext CreateContext(Type type) { var context = ContextTool.CreateContext(type); var services = ((IAccessor <IServiceProvider>)context).Service; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); loggerFactory.AddProvider(_loggerProvider); return(context); }
private DbContext CreateContext(Type type) { var context = ContextTool.CreateContext(type); var extension = RelationalOptionsExtension.Extract(context.Configuration); if (extension.MigrationAssembly == null) { extension.MigrationAssembly = _assembly; } return(context); }
private DbContext CreateContext(Type type) { var context = ContextTool.CreateContext(type); var scopedServiceProvider = ((IDbContextServices)context).ScopedServiceProvider; var options = scopedServiceProvider.GetRequiredService <DbContextService <IDbContextOptions> >(); var loggerFactory = scopedServiceProvider.GetRequiredService <ILoggerFactory>(); loggerFactory.AddProvider(_loggerProvider); var extension = MigrationsOptionsExtension.Extract(options.Service); if (extension == null || extension.MigrationAssembly == null) { options.Service.AddOrUpdateExtension <MigrationsOptionsExtension>( x => x.MigrationAssembly = _assembly); } return(context); }
protected virtual DbContext CreateContext(Type type, string startupAssemblyName) { var context = new ContextTool(_services).CreateContext(type, startupAssemblyName); var services = ((IAccessor<IServiceProvider>)context).Service; var loggerFactory = services.GetRequiredService<ILoggerFactory>(); loggerFactory.AddProvider(_loggerProvider); return context; }
// TODO: Find from migration types instead (See #628) public virtual IEnumerable <Type> GetContextTypes() { return(ContextTool.GetContextTypes(_assembly)); }
public virtual Type GetContextType([CanBeNull] string name) { return(ContextTool.SelectType(GetContextTypes(), name)); }