How to set ViewBag properties for all Views without using a base class for Controllers?

The best way is using the ActionFilterAttribute. I’ll show you how to use it in .Net Core and .Net Framework. .Net Core 2.1 & 3.1 public class ViewBagActionFilter : ActionFilterAttribute { public ViewBagActionFilter(IOptions<Settings> settings){ //DI will inject what you need here } public override void OnResultExecuting(ResultExecutingContext context) { // for razor pages if (context.Controller is … Read more

Does Ninject support Func (auto generated factory)?

NB Ninject 3.0 and later has this fully supported using the Ninject.Extensions.Factory package, see the wiki:- https://github.com/ninject/ninject.extensions.factory/wiki EDIT: NB there is a Bind<T>().ToFactory() implementation in Ninject 2.3 (which is not a fully tests supported release but is available from the CodeBetter server) Ninject does not support this natively at the moment. We planned to add … Read more