它們之間有什麼區別: 差異
我需要
- Unity.AspNet.WebApi
- Unity.WebForms
- Microsoft.Practices.Unity.WebApi ,即1 & 2如果我想在WebAPI的webforms應用程序中使用DI?
爲什麼不只是使用Microsoft.Practices.Unity,是不是這個足以在各種情況下實現D的庫?
編輯: 爲什麼Unity.WebForms建立控制樹,如果你只想爲你的IRepository使用DI?
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]); } }