Hello, I have a situation where i need to inject or access my EF DbContext from controller, please let me know how to access it . I have tried the below var ctx = IocManager.Instance.Resolve<PLCMDbContext>(); it gives error that it had depedency on options
Also I tried controller construction inject and get same error. public constructor( IDbContextProvider<MyDbContext> dbContextProvider) { _ctx = dbContextProvider.GetDbContext(); }
get same error message.
Thanks
3 Answer(s)
-
0
You should use repositories instead of DbContext. Of course repositories can also get DbContext.
using Abp.EntityFrameworkCore.Repositories; _xxxRepository.GetDbContext()
-
0
Where do i use this code? in controller? How do inject _xxxRepository into controller? Any example would help. we are using asp.net core and jquery
Thanks v
-
0
Hi,
You can check injection sample here https://aspnetboilerplate.com/Pages/Documents/Repositories.
You can inject it to your Controller.