我有BaseController
,并且有property
RunTimeContext
public class BaseController : Controller
{
public IRunTimeContext RunTimeContext {get;set;}
}
我的方法OnActionExecuting
使用RunTimeContext
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
_logRequest = new LogRequest
{
TenantId = RunTimeContext.TenantId
}
base.OnActionExecuting(filterContext);
}
但是,我的RunTimeContext
永远是null
我的autofac配置是:
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterType<RunTimeContext>().As<IRunTimeContext>().PropertiesAutowired();
答案 0 :(得分:0)
您应该将.PropertiesAutowired()
添加到控制器注册,而不是RunTimeContext
类型注册,因为您希望设置控制器的属性,而不是RunTimeContext
:
builder.RegisterControllers(typeof(MvcApplication).Assembly).PropertiesAutowired();