使用autofac将属性注入到asp.net页面:重写PropertyInjectionModule行为以注入值/设置
|
是否可以通过autofac的PropertyInjectionModule将值/设置注入ASP.NET页?我的印象是,默认处理程序行为是搜索属性并找到与容器中的服务匹配的任何类型。
例如页面:
public class MyPage: System.Web.UI.Page {
public IDataProvider DataProvider { get; set; }
public bool SomeSetting {get; set; }
public bool AnotherSetting { get; set; }
public string MySettings { get; set; }
// stuff
}
我想也许您可以指定属性:
builder.RegisterType<MyPage>()
.WithProperty(\"SomeSetting\", true)
.WithProperty(\"AnotherSetting\", false)
.WithProperty(\"MySettings\", \"do-re-mi\");
但它似乎不起作用。
我意识到我可以设置IMyPageConfig接口并以这种方式提供设置,但是这些是可选属性,可能需要设置也可以不需要设置。
没有找到相关结果
已邀请:
1 个回复
宦哨抹存胳