Open Closed

How do I Inject/ access my EFDbContext from controller #8736

mhdevelop created

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.


3 Answer(s)
  • 0
    maliming created

    You should use repositories instead of DbContext. Of course repositories can also get DbContext.

    using Abp.EntityFrameworkCore.Repositories;
  • 0
    mhdevelop created

    Where do i use this code? in controller? How do inject _xxxRepository into controller? Any example would help. we are using core and jquery

    Thanks v

  • 0
    ismcagdas created


    You can check injection sample here

    You can inject it to your Controller.