|
@@ -1,8 +1,12 @@
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Quadarax.Application.QLiberace.Base.Entities;
|
|
using Quadarax.Application.QLiberace.Base.Entities;
|
|
|
|
|
+using Quadarax.Application.QLiberace.Common.Attributes;
|
|
|
|
|
+using Quadarax.Application.QLiberace.Common.Configuration;
|
|
|
|
|
+using Quadarax.Foundation.Core.Reflection;
|
|
|
|
|
|
|
|
namespace Quadarax.Application.QLiberace.Base
|
|
namespace Quadarax.Application.QLiberace.Base
|
|
|
{
|
|
{
|
|
|
|
|
+ [DbContextModuleAssignment(Constants.Modules.Base.Code)]
|
|
|
public class QlbrcDbContext : DbContext
|
|
public class QlbrcDbContext : DbContext
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -26,9 +30,17 @@ namespace Quadarax.Application.QLiberace.Base
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
{
|
|
{
|
|
|
- optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=QLiberace;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
|
|
|
|
|
|
|
+ optionsBuilder.UseSqlServer(GetConnectionString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private string GetConnectionString()
|
|
|
|
|
+ {
|
|
|
|
|
+ var attr = AttributeQuery<DbContextModuleAssignmentAttribute>.Get(typeof(QlbrcDbContext));
|
|
|
|
|
+ if (attr == null)
|
|
|
|
|
+ throw new InvalidOperationException($"No connection string defined for DbContext {this.GetType().Name} or DbContextModuleAssignment is missing.");
|
|
|
|
|
+
|
|
|
|
|
+ return OlbrcConfiguration.Get(attr.ModuleCode).ConnectionString;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|