Digbyswift is based in Leeds, West Yorkshire offering web and digital solutions. With over a decade of experience in corporate and agency web development, Digbyswift can meet and support your requirements, whether it be MVC or web forms development, Umbraco, bespoke CMS build and maintenance, ecommerce, SEO and Google analytics or even client training. Read more ...

Upgrading to MVC2: No parameterless constructor error

By Digbyswift at February 25, 2010 10:00

I cam across this today and it bugged the hell out of me. I am using a custom ControllerFactory (kindly provided by Steve Sanderson’s awesome Pro ASP.NET MVC Framework) set in the global.asax.cs as such:

protected void Application_Start() 
{ 
    RegisterRoutes(RouteTable.Routes); 

    // Configure log4net 
    log4net.Config.XmlConfigurator.Configure(); 

    // Configure CastleWindsor 
    ControllerBuilder
        .Current
        .SetControllerFactory(new WindsorControllerFactory()); 
}

During the upgrade this stopped working and i started getting the following error:

System.MissingMethodException: No parameterless constructor defined for this object


I tracked the error down to the fact the constructors in my Controllers were not being initialized and I found the following quote from the breaking changes section of the What’s New in ASP.NET MVC 2:

Custom controller factories are often used to provide dependency injection for ASP.NET MVC applications. To update the custom controller factories to support ASP.NET MVC 2, change the method signature or signatures to match the new signatures, and use the request context parameter instead of the property.

After a little digging, the only change I needed to make was altering my custom ControllerFactory’s GetControllerInstance() override from:

protected override IController GetControllerInstance(Type controllerType) 
{ 
    return (IController)_container.Resolve(controllerType); 
}


to

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) 
{ 
    return (IController)_container.Resolve(controllerType); 
}

So many projects, so little time – NHibernate membership provider first

By Digbyswift at January 17, 2010 14:17

I know I have to finish off building my NHibernate-based Membership provider – its about 75% there, but I also want to start writing a bug tracker, a CRM (which may as well include the bug tracker), a light weight CMS and actually post relevant stuff to this website …

First things first. I’ll get the membership provider out of the way.

Hopefully I’ll post something about that later. Basically, the Membership provider that ships with .Net2.0 is fine but I need it to do more.

I need mine to be able to:

  • Handle user session objects as well as simple logged in/out cookies;
  • Have a more robust security question/answer model;
  • Handle a slightly more complex user model, i.e. one with multiple addresses, contact details etc.
  • Be more compact and contained, i.e. I don’t want to have to keep writing the code that should already be in the provider.

I know these are straight forward but I want them to be out of the box when I plug my provider in.Finally, an ex-colleague implemented a means of preventing session hijacking which I want to have a stab, and do it at without using databases if at all possible.