【发布时间】:2019-10-28 20:13:52
【问题描述】:
我在一个 ASP.NET Webforms 项目中工作,并且正在使用 Unity 进行 DI。 该项目还使用了 DevExpress ASP.NET Ajax 控件。
现在我们遇到了问题,似乎是 DevExpress 和 Unity 之间的冲突。
这是 Unity 配置
[assembly: WebActivator.PostApplicationStartMethod(typeof(Sales.Web.App_Start.UnityWebFormsStart), "PostStart")]
namespace Sales.Web.App_Start
{
/// <summary>
/// Startup class for the Unity.WebForms NuGet package.
/// </summary>
internal static class UnityWebFormsStart
{
/// <summary>
/// Initializes the unity container when the application starts up.
/// </summary>
/// <remarks>
/// Do not edit this method. Perform any modifications in the
/// <see cref="RegisterDependencies" /> method.
/// </remarks>
internal static void PostStart()
{
IUnityContainer container = new UnityContainer();
HttpContext.Current.Application.SetContainer(container);
RegisterDependencies(container);
}
/// <summary>
/// Registers dependencies in the supplied container.
/// </summary>
/// <param name="container">Instance of the container to populate.</param>
private static void RegisterDependencies(IUnityContainer container)
{
// TODO: Add any dependencies needed here
container
.RegisterType<IDbFactory, DbFactory>(new HierarchicalLifetimeManager())
.RegisterType(typeof(IDbProxy<>), typeof(DbProxy<>))
.RegisterType<IErpData, ErpData>(new HierarchicalLifetimeManager())
.RegisterType<ICaseData, CaseData>(new HierarchicalLifetimeManager())
.RegisterType<ICaseCauseData, CaseCauseData>(new HierarchicalLifetimeManager())
.RegisterType<ICaseHandler, CaseHandler>(new HierarchicalLifetimeManager());
}
}
}
任何 Unity 配置都与 DevExpress 控件无关,但我认为它与 HttpContext 对象挂钩。
只有当我使用 DevExpress 的 TabControl 时才会出现此错误,所有其他控件都可以正常工作。
查看附件图片,更详细地描述错误消息。
【问题讨论】:
标签: c# asp.net dependency-injection unity-container