using adddbcontext on the application service provider code example
Example: c# services.adddbcontext
public void ConfigureServices(IServiceCollection services)
{
var connectionString = "connection string to database";
services.AddDbContext<MyContext>(ServiceLifetime.Scoped);
}