I am trying to use the secrets stored in Azure Key Vault. I first created a connection resolver :
public class KeyValutConnectionResolver : DefaultConnectionStringResolver, IDbPerTenantConnectionStringResolver
{
/// <summary>
/// Reference to the session.
/// </summary>
public IAbpSession AbpSession { get; set; }
private readonly ICurrentUnitOfWorkProvider _currentUnitOfWorkProvider;
private readonly ITenantCache _tenantCache;
private readonly IConfiguration _configuration;
/// <summary>
/// Initializes a new instance of the <see cref="DbPerTenantConnectionStringResolver"/> class.
/// </summary>
public KeyValutConnectionResolver(
IAbpStartupConfiguration configuration,
ICurrentUnitOfWorkProvider currentUnitOfWorkProvider,
ITenantCache tenantCache, IConfiguration configuration1)
: base(
configuration)
{
_currentUnitOfWorkProvider = currentUnitOfWorkProvider;
_tenantCache = tenantCache;
_configuration = configuration1;
AbpSession = NullAbpSession.Instance;
}
public override string GetNameOrConnectionString(ConnectionStringResolveArgs args)
{
return args.MultiTenancySide == MultiTenancySides.Host ? _configuration["ConnectionStrings:Default"] : GetNameOrConnectionString(new DbPerTenantConnectionStringResolveArgs(GetCurrentTenantId(), args));
}
public virtual string GetNameOrConnectionString(DbPerTenantConnectionStringResolveArgs args)
{
if (args.TenantId == null)
{
//Requested for host
return base.GetNameOrConnectionString(args);
}
var tenantCacheItem = _tenantCache.Get(args.TenantId.Value);
if (tenantCacheItem.ConnectionString.IsNullOrEmpty())
{
//Tenant has not dedicated database
return base.GetNameOrConnectionString(args);
}
return tenantCacheItem.ConnectionString;
}
protected virtual int? GetCurrentTenantId()
{
return _currentUnitOfWorkProvider.Current != null
? _currentUnitOfWorkProvider.Current.GetTenantId()
: AbpSession.TenantId;
}
}
In EntityFrameworkCore Module Pre-Initialize :
Configuration.ReplaceService<IConnectionStringResolver, KeyValutConnectionResolver>(DependencyLifeStyle.Transient);
When I debug the connection string i Get is from KeyVault but then i don't know where it gets replaced from Appsettings.json.
public EDRMSDbContext(DbContextOptions<EDRMSDbContext> options)
: base(options)
{
// I get the cinnection from KeyVault
}
Any updates?
Done
Can you send me an email to share the link to the project , i have already shared it with Elsa to look into it ?
This is what is happening :
Elsa creates a MapperConfiguration and uses it to create an IMapper, which is registered with IoC. ABP also creates a MapperConfiguration and uses it to create an IMapper, which is also registered. Because the one from Elsa is registered first, anytime something resolves/injects IMapper, it receives the instance from Elsa, which does not contain any of the mapping configuration from ABP.
Any idea or suggestion you can think of ?
I am also on the same boat. Any step by step help is appreciated
Yes I am using Hangfire.MySqlStorage.
MySql version is 8.0>
I am using EFCore and My SQL
public class Po_approval_assignment : Entity , IMayHaveTenant
{
[StringLength(Po_approval_assignmentConsts.Maxcreated_byLength, MinimumLength = Po_approval_assignmentConsts.Mincreated_byLength)]
public virtual string created_by { get; set; }
public virtual DateTime? created_date { get; set; }
public virtual DateTime? last_modified_date { get; set; }
[StringLength(Po_approval_assignmentConsts.Maxmodified_byLength, MinimumLength = Po_approval_assignmentConsts.Minmodified_byLength)]
public virtual string modified_by { get; set; }
[ForeignKey("po_Approval_Rule")]
public virtual long po_approval_rule_id { get; set; }
public Po_approval_rule po_Approval_Rule { get; set; }
[ForeignKey("po_Reviewer")]
public virtual long po_reviewer_id { get; set; }
public Po_reviewer po_Reviewer { get; set; }
public virtual int? version { get; set; }
[Column("tenant_id")] public int? TenantId { get; set; }
}
I am trying to create a composite primary key using po_approval_rule_id and po_reviewer_id
Thank You it worked.
You can close this. I wasn;t using gulp so it wasn't minifying