I'm using a BasePageModel class to hold common code and properties. The subclasses get the DI injected objects and then pass them up to the base class which handles them with an optional parameters list. There might be more elegant way to accomplish this but this is working well for me.
public class BasePageModel : PageModel {
public BasePageModel(params object[] list) {
foreach (var item in list) {
if (item is ILoggerFactory loggerFactory) {
_logger = loggerFactory.CreateLogger("Projects");
}
if (item is ApplicationDbContext context) {
_dbContext = context;
}
if (item is UserManager<ApplicationUser> manager) {
_userManager = manager;
}
if (item is IHostingEnvironment env) {
_environment = env;
}
}
}
public class IndexModel : BasePageModel {
public IndexModel(ApplicationDbContext context, UserManager<ApplicationUser> userManager, ILoggerFactory loggerFactory) :
base(context, userManager, loggerFactory) { }
}