据我所见,我无法从此方法访问注入的IConfiguration对象。而且,据我所知,没有办法访问HttpContext并从中获取。有没有简单的方法可以获取存储在appsettings.json中的连接字符串?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Projekt.Models;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http;
namespace Project.DAL
{
public class UserContext : DbContext
{
public DbSet<User> Users {get;set;}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connection_string = ""; //connection string from appsettings.json
optionsBuilder.UseSqlServer(connection_string);
}
public class User {
public string login{ get; set; }
public string password { get; set; }
}
}
}