I'm working at a ASP.NET Webforms project and is using Unity for DI. This project also use DevExpress ASP.NET Ajax Controls.
Now we have run into problem and it seems to be a conflict between DevExpress and Unity.
This is the Unity configuration
[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());
}
}
}
Any of this Unity configuration has nothing to do with the DevExpress controls, but i think it hooks up the HttpContext object.
And this error appears only when i use the TabControl from DevExpress, all other controls works well.
See the attached image that describe the error message more in detail.
By convention, Unity prefers the constructor with the longest parameter list if no other configuration was supplied. Having two constructors with parameter list of equal length creates an ambiguity, so Unity throws an exception. That's why it cannot resolve the control you are using.
You can explicitly tell Unity which constructor to prefer:
container.RegisterType<IService, Service>(new InjectionConstructor(typeof(IServiceDependency)));
You can use the [InjectionConstructor] attribute on the contructor wanted
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With