Hi All,
I am migrating one asp.net core 3.1 from asp.net project. Here i have one dbcontext which connection string i need to pass from one of my appservice class. To use appservice, in this dbcontext i used something like below:
public class MyContext: DbContext
{
private readonly IAppSetting _appSetting;
public MyContext(IAppSetting appSetting)
{
_appSetting = appSetting;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_appSetting.Myconnectionstring, opts=> opts.CommandTimeout((int)TimeSpan.FromMinutes(1).TotalSeconds));
}
}
In StartUp.cs file i have configure this context service like below:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyContext>();
}
But when i run the application it is throwing runtime error like :
Some services are not able to be constructed dbcontext.
Need help.
