I decided to use this AddDbContext method to add and setup my context for my Entity Framework Core project using ODataController
services.AddDbContext<ExampleContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ExampleConnection")));
// https://stackoverflow.com/a/51970589/196526
I suppose this AddDbContext
allow us to add a global context and it is possible to retrieve it later when required in my controller or service class. How can I use it?
At this moment I pass my context each time.
public class StudentsController : ODataController { private readonly ExampleContext _context;
public StudentsController(ExampleContext context)
{
_context = context;
}
}
I would like to get load my context without having to pass it to my controller. I'm using ODataController.