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

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

            return(contextType);
        }
Esempio n. 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();
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
        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));
 }