Note that there are some explanatory texts on larger screens.

plurals
  1. POSportsStore: MVC programming issue [Castle WindsorControllerFactory]
    primarykey
    data
    text
    <p>So I've been following Steven Sanderson's book called Pro ASP.NET MVC Framework, and I'm running into an exception:</p> <pre><code>No parameterless constructor defined for this object. 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.MissingMethodException: No parameterless constructor defined for this object. Source Error: Line 16: HttpContext.Current.RewritePath(Request.ApplicationPath, false); Line 17: IHttpHandler httpHandler = new MvcHttpHandler(); Line 18: httpHandler.ProcessRequest(HttpContext.Current); Line 19: HttpContext.Current.RewritePath(originalPath, false); Line 20: } Source File: C:\Users\Stephen\Documents\Visual Studio 2008\Projects\SportsStore\WebUI\Default.aspx.cs Line: 18 </code></pre> <p>Here's my WindsorControllerFactory code:</p> <pre><code>public class WindsorControllerFactory : DefaultControllerFactory { WindsorContainer container; // The constructor // 1. Sets up a new IoC container // 2. Registers all components specified in web.config // 3. Registers all controller types as components public WindsorControllerFactory() { // Instantiate a container, taking configuration from web.config container = new WindsorContainer( new XmlInterpreter(new ConfigResource("castle")) ); // 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.AddComponentWithLifestyle(t.FullName, t, Castle.Core.LifestyleType.Transient); } // Constructs the controller instance needed to service each request protected override IController GetControllerInstance(Type controllerType) { return (IController)container.Resolve(controllerType); } } </code></pre> <p>My Global.asax.cs code:</p> <pre><code>protected void Application_Start() { RegisterRoutes(RouteTable.Routes); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory()); } </code></pre> <p>And the web.config values:</p> <pre><code>&lt;configSections&gt; &lt;section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/&gt; &lt;/configSections&gt; &lt;castle&gt; &lt;properties&gt; &lt;myConnStr&gt;Server=.\SQLEXPRESS;Database=SportsStore;Trusted_Connection=yes;&lt;/myConnStr&gt; &lt;/properties&gt; &lt;components&gt; &lt;component id="ProdsRepository" service="DomainModel.Abstract.IProductsRepository, DomainModel" type="DomainModel.Concrete.SqlProductsRepository, DomainModel"&gt; &lt;parameters&gt; &lt;connectionString&gt;#{myConnStr}&lt;/connectionString&gt; &lt;/parameters&gt; &lt;/component&gt; &lt;/components&gt; &lt;/castle&gt; </code></pre> <p>Thanks all! -Steve</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload