I am using the MvcContrib library with Castle Windsor and I am having a problem with setting a parameter when I register a component.
I have the following interfaces for classes that wrap a DataContext. I want to be able to specify which DataContext to use for different services because I am connecting 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
{
公共的 IDataContext DC { 获取; 设置; }
public Repository(IDataContext dataContext)
{
DC = dataContext;
}
}
这是来自我的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
);
当我尝试加载页面时,出现以下错误。
"Key invalid for parameter dataContext. Thus the kernel was unable to override the service dependency"