我刚刚开始使用 Autofac,我有以下代码:
public class _default : System.Web.UI.Page, IUserInformationProvider
{
protected void Page_Load(object sender, System.EventArgs e)
{
ControllerFactory cf;
using (scope == ((Global_asax)this.Context.ApplicationInstance).ContainerProvider.ApplicationContainer.BeginLifetimeScope()) {
cf = scope.Resolve<IControllerFactory>(); // <-- would love to pass "this" somewhere here, but how???
}
}
}
ControllerFactory 在下面定义,也采用 IUserInformationProvider 接口。我想将 WebForm 的实例作为参数传递给 Resolve IControllerFactory。
public class ControllerFactory : IControllerFactory
{
protected IUserInformationProvider _userInformation;
public ControllerFactory(IUserInformationProvider userInformation)
{
_userInformation = userInformation;
}
}
查看文档,我看到有 3 种参数类型(Named、Typed、Resolved),但前两种只采用常量值。似乎已解决的参数是要走的路,但是我对如何实现它或者这是否是正确的策略有点迷茫。builder.Register 会是什么样子?