Пример #1
0
 public virtual IEnumerable <Type> GetContextTypes() =>
 ContextTool.GetContextTypes(_assembly)
 .Concat(
     MigrationAssembly.GetMigrationTypes(_assembly)
     .Select(MigrationAssembly.TryGetContextType)
     .Where(t => t != null))
 .Distinct();
Пример #2
0
        public virtual Type GetContextType([CanBeNull] string name)
        {
            var contextType = ContextTool.SelectType(GetContextTypes(), name);

            _logger.Value.LogVerbose(Strings.LogUseContext(contextType.Name));

            return(contextType);
        }
Пример #3
0
 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();
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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));
 }
Пример #10
0
 public virtual Type GetContextType([CanBeNull] string name)
 {
     return(ContextTool.SelectType(GetContextTypes(), name));
 }