2

I am using Razorpages in ASP.NET Core I have a simple detailsModel that brings in the different DbContext from Entity Framework (EF) using the constructor parameters.

this means that my DbContexts are available when performing different actions using the OnGetVerb and OnPostVerb.

I have created a helper class that I want to use to execute the actions as I need to call this code from other places as well, but when I call the helper class the DbContext is not available in the helper class.

await new Helpers.ApproveOrder().Approve(id);

This is my code

public class DetailsModel : PageModel {

        public Context1 _context1;
        public Context2 _context2;
        public Context3 _context3;
        public IMemoryCache _cache;


        public DetailsModel(Context1 context1, Context2 context2, Context3 context3, IMemoryCache memoryCache) {
            _context1 = context1;
            _context2 = context2;
            _context3 = context3;
            _cache = memoryCache;
        }

        public async Task<IActionResult> OnGetApproveAsync(int id) {

            await new Helpers.ApproveOrder().Approve(id);
            return Redirect("~/");
        }
    }

how can I fix this so that my dbContexts are also available in my helper class

Thomas Adrian
  • 3,543
  • 6
  • 32
  • 62

0 Answers0