问题
I am trying to following book : Pro ASP.NET MVC Framework by Steven Sanderson...
The line container = new WindsorContainer(xi);
produces this error:
Could not convert from 'DomainModel.Abstract.IPeopleRepository, DomainModel' to System.Type - Maybe type could not be found**
public WindsorControllerFactory()
{
ConfigResource confres = new ConfigResource("castle");
XmlInterpreter xi = new XmlInterpreter(confres);
container = new WindsorContainer(xi);
// Also register all the controller types as transient
var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IController).IsAssignableFrom(t)
select t;
foreach (Type t in controllerTypes)
{
container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
}
}
The castle config:
<castle>
<components>
<component id="PeopleRepository"
service="DomainModel.Abstract.IPeopleRepository, DomainModel"
type="DomainModel.Concrete.FakePeopleRepository, DomainModel"
>
How can this be fixed?
回答1:
Sanderson's book is outdated about the MVC-Windsor integration. Don't code your own (or the book's) controller factory. Use MVCContrib's Windsor integration instead.
Also, registering controllers within the controller factory is plain bad practice. The controller factory is there to instantiate controllers, not to manage container registrations.
UPDATE: MvcContrib for ASP.NET MVC 3 removed all controller factories and deprecated all IoC integrations.
回答2:
I'd lose the empty PeopleController
constructor
来源:https://stackoverflow.com/questions/4103383/creating-windsorcontainer-results-in-type-conversion-error