j'ai suivi le livre de Steven Sanderson appelé Pro Framework ASP.NET MVC, et je suis en cours d'exécution en une exception:SportsStore: programmation MVC
Could not load type 'DomainModel.Abstract.IProductsRepository' from assembly 'DomainModel'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'DomainModel.Abstract.IProductsRepository' from assembly 'DomainModel'
.
Line 19: public WindsorControllerFactory()
Line 20: {
Line 21: container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
Line 22:
Line 23: var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t;
Voici mon code WindsorControllerFactory:
public class WindsorControllerFactory : DefaultControllerFactory
{
WindsorContainer container;
public WindsorControllerFactory()
{
container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
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);
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return (IController)container.Resolve(controllerType);
}
}
Code Mon Global.asax.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
}
Et les valeurs web.config:
<configSections>
< section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
</configSections>
<castle>
<components>
<component id="ProdsRepository" service="DomainModel.Abstract.IProductsRepository, DomainModel"
type="DomainModel.Concrete.SqlProductsRepository, DomainModel">
<parameters>
< connectionString>data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SportsStore.mdf;User Instance=true< /connectionString>
</parameters>
</component>
</components>
</castle>
Ma question est pourquoi ne pouvait pas charger le type 'Do mainModel.Abstract.IProductsRepository 'à partir de l'assembly' DomainModel '. ?