C#C
C#3y ago
BekirK

❔ Getting the connectionString from appsetting.json

Hello everyone, in my project I am using a Generic build like this:
public class EfGenericRepository<TEntity, TContext> : IGenericRepository<TEntity> where TEntity : class, IEntity, new() where TContext : DbContext, new() { public void Add(TEntity entity) { using (TContext context = new TContext()) { var addedEntity = context.Entry(entity); addedEntity.State = EntityState.Added; context.SaveChanges(); } } }
Any EntityDal class is like this:
public class EfCategoryDal : EfGenericRepository<Category, SimpraProjectContext>, ICategoryDal { }
Context class is like this
public class SimpraProjectContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(@"Server=DESKTOP-xxx; Database=TestOne; Trusted_Connection=true; TrustServerCertificate=True"); } // other codes }
I couldn't perform the necessary operations to get the connectionString from appsetting.json. Can you help with this. (I'm using .net 6)
Was this page helpful?