Remove DbConfig and new constructors on DbContextBase and refactor Migrations to use explcit generation of IOqtaneDatabase instance
This commit is contained in:
@ -6,6 +6,7 @@ using Oqtane.Repository;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Modules.HtmlText.Repository;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Enums;
|
||||
@ -18,12 +19,15 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
public class HtmlTextManager : MigratableModuleBase, IInstallable, IPortable
|
||||
{
|
||||
private readonly IHtmlTextRepository _htmlText;
|
||||
private readonly IEnumerable<IOqtaneDatabase> _databases;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, IEnumerable<IOqtaneDatabase> databases)
|
||||
|
||||
public HtmlTextManager(IHtmlTextRepository htmlText, ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_htmlText = htmlText;
|
||||
_databases = databases;
|
||||
_tenantManager = tenantManager;
|
||||
_accessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public string ExportModule(Module module)
|
||||
@ -57,14 +61,12 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||
|
||||
public bool Install(Tenant tenant, string version)
|
||||
{
|
||||
var dbConfig = new DbConfig(null, null, _databases) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
return Migrate(new HtmlTextContext(dbConfig, null), tenant, MigrationType.Up);
|
||||
return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Up);
|
||||
}
|
||||
|
||||
public bool Uninstall(Tenant tenant)
|
||||
{
|
||||
var dbConfig = new DbConfig(null, null, _databases) {ConnectionString = tenant.DBConnectionString, DatabaseType = tenant.DBType};
|
||||
return Migrate(new HtmlTextContext(dbConfig, null), tenant, MigrationType.Down);
|
||||
return Migrate(new HtmlTextContext(_tenantManager, _accessor), tenant, MigrationType.Down);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Oqtane.Modules.HtmlText.Migrations
|
||||
[Migration("HtmlText.01.00.00.00")]
|
||||
public class InitializeModule : MultiDatabaseMigration
|
||||
{
|
||||
public InitializeModule(IEnumerable<IOqtaneDatabase> databases) : base(databases)
|
||||
public InitializeModule(IOqtaneDatabase database) : base(database)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
@ -10,9 +11,7 @@ namespace Oqtane.Modules.HtmlText.Repository
|
||||
{
|
||||
public class HtmlTextContext : DBContextBase, IService, IMultiDatabase
|
||||
{
|
||||
public HtmlTextContext(IDbConfig dbConfig, ITenantManager tenantManager) : base(dbConfig, tenantManager)
|
||||
{
|
||||
}
|
||||
public HtmlTextContext(ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor) : base(tenantManager, httpContextAccessor) { }
|
||||
|
||||
public virtual DbSet<Models.HtmlText> HtmlText { get; set; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user