'Unit of work pattern not allowing me to create db context without options

I am using ef core and I am trying to implement the repository pattern as part of best practices. But I am we bit confused on the context normally I would create the context in the and inject

HomeController(WarehouseDBContext _context)

I have created my unitOfWork Class as suggested by the docs here https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application#creating-the-unit-of-work-class

However I am tad confused. It's expecting options here which is normally handled on the controller.

My UnitOfWork class

public class WarehouseUnitOfWork : IDisposable
{
    private WarehouseDBContext context = new WarehouseDBContext();
    private WarehouseRepository<StockItem> stockRepository;
 

    public WarehouseRepository<StockItem> StockRepoistry
    {
        get
        {

            if (this.stockRepository == null)
            {
                this.stockRepository = new WarehouseRepository<StockItem>(context);
            }
            return stockRepository;
        }
    }
    public void Save()
    {
        context.SaveChanges();
    }

    private bool disposed = false;

    protected virtual void Dispose(bool disposing)
    {
        if (!this.disposed)
        {
            if (disposing)
            {
                context.Dispose();
            }
        }
        this.disposed = true;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
}

But here it is complain that it expect options which would I presume contain the connection string. I am trying to decouple my code from EF so that If I want to upgrade in the future will be easier. My WareshouseDBContext is describe below

As you can see it is expecting options. What should I pass through here?

namespace WareHouseDal.Dal {
 public class WarehouseDBContext : IdentityDbContext<ApplicationUser> {
      public WarehouseDBContext(DbContextOptions<WarehouseDBContext> options)
        : base(options) {
        
    }

    public DbSet<WarehouseCrm> Warehouse { get; set; }
    public DbSet<Company> Companies { get; set; }
 }

}

When I used to create my context before I just used the singleton pattern of

private readonly WarehouseDBContext _context;

Is their something else I need to do to allow it to accept the creation of the context on the unit of work level.

Error being given is

enter image description here



Solution 1:[1]

I agree Ardalis repository is a great tutorial/example, in case if anyone want a lite solution to implement the Repository and Unit of Work Patterns in EF 5/EF 6.

you may check out the below one, I tested it would work in EF Core 6

https://pradeepl.com/blog/repository-and-unit-of-work-pattern-asp-net-core-3-1/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Keith POON