I am using the MvcContrib library with Castle Windsor and I have a problem setting a parameter when I register a component.
I have the following interfaces for classes that wrap a DataContext. I want to indicate which DataContext to use for different services, because I connect to several databases to retrieve data.
public interface IDataContext
{
DataContext Context { get; }
}
public interface IReportingDC : IDataContext
{
}
public class Repository<T> : IRepository<T> where T : class
{
public IDataContext DC {get; set; }
public Repository(IDataContext dataContext)
{
DC = dataContext;
}
}
Here are the registration lines from my global.asax.cs.
container.AddComponentLifeStyle<IDataContext, MainDataContext>(Castle.Core.LifestyleType.PerWebRequest);
container.AddComponentLifeStyle<IReportingDC, ReportingDC>(Castle.Core.LifestyleType.PerWebRequest);
container.Register(Component.For<IRepository<ReportingTotals>>()
.ImplementedBy<Repository<ReportingTotals>>()
.Parameters(Parameter.ForKey("dataContext").Eq("IReportingDC"))
.LifeStyle.PerWebRequest
);
When I try to load the page, I get the following error.
"The key is not valid for the dataContext parameter. Therefore, the kernel was unable to override the service dependency"