Example #1
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);
        }
Example #3
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);
        }