【发布时间】:2015-04-02 20:44:07
【问题描述】:
它们有什么区别:
- Unity.AspNet.WebApi
- Unity.WebForms
- Microsoft.Practices.Unity.WebApi
如果我想在带有 WebAPI 的 webforms 应用程序中使用 DI,我需要 1 和 2 吗?
为什么不直接使用Microsoft.Practices.Unity,这个lib还不足以在各种场景下实现D吗?
编辑: 例如,如果您只想为您的 IRepository 提供 DI,为什么 Unity.WebForms 会构建控件树?
private void OnPageInitComplete(object sender, EventArgs e)
{
foreach (Control controlTree in UnityHttpModule.GetControlTree((Page)sender))
{
string fullName = controlTree.GetType().FullName ?? string.Empty;
string str = (controlTree.GetType().BaseType != null ? controlTree.GetType().BaseType.FullName : string.Empty);
if (!this.Prefixes.All<string>((string p) => !fullName.StartsWith(p)) || !this.Prefixes.All<string>((string p) => !str.StartsWith(p)))
{
continue;
}
UnityContainerExtensions.BuildUp(this.ChildContainer, controlTree.GetType(), controlTree, new ResolverOverride[0]);
}
}
【问题讨论】:
标签: asp.net-mvc asp.net-web-api webforms unity-container