internal static UnitOfWork <ReadModelUpdate> EnsureDbContextIsInitialized( this UnitOfWork <ReadModelUpdate> unitOfWork, Func <DbContext> createDbContext) { if (unitOfWork.Resource <DbContext>() == null) { var dbContext = createDbContext(); // index the resource under DbContext... unitOfWork.AddResource(dbContext, true); // ...and other the actual registered type, if different, since callers will access it this way var actualType = dbContext.GetType(); if (actualType != typeof(DbContext)) { unitOfWork.AddResource(actualType, dbContext, false); } } return(unitOfWork); }