title: ASP.NET MVC with Spring.NET and ModelBinder
body: <p>I'm working on a demo that makes use of Spring.NET IoC capability in ASP.NET MVC . It's kind of like the MyBlog application presented on pair programming video tutorial on www.asp.net site. I've completed the same demo using Microsoft's Unity framework and now want to try out the Spring container.
  To that end I've implemented a simple IControllerFactory that first creates the Spring object factory like that:</p>
  
  <pre><code>IObjectFactory factory;
  (....)
  factory = new XmlObjectFactory(new FileSystemResource(application.Server.MapPath("objects.xml")))
  </code></pre>
  
  <p>and next it gets the controller from that factory like that:</p>
  
  <pre><code>public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) {
      IController result = context.GetObject(controllerName) as IController;
      return result;
  }
  </code></pre>
  
  <p>(error handling stripped for simplification purposes).</p>
  
  <p>Now somewhere in my HomeController I have this kind of action:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
  public ActionResult AddEntry([Bind] BlogEntry entry, int id) {
      entry.EntryDate = DateTime.Now;
  ....
  </code></pre>
  
  <p>And here's the part of AddEntry.aspx view that defines the editors for entry parameter (really basic stuff):</p>
  
  <pre><code>&lt;form method="post" action="/Home/AddEntry/&lt;%= ViewData["id"] %&gt;"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label for="Title"&gt;Title&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="entry.Title" type="text"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;label for="Text"&gt;Content&lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="entry.Text" type="text"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;br /&gt;
      &lt;input type="submit" value="Add entry" /&gt;
      &lt;input type="button" value="Cancel" onclick="history.back(-1);" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Now here's the deal: 
  When I'm using the Unity IoC it works like a charm. "entry" parameter gets deserialized from my form like it should and the line</p>
  
  <pre><code>entry.EntryDate = DateTime.Now; 
  </code></pre>
  
  <p>completes without problems.</p>
  
  <p>However when I switch to Spring.NET object factory (like described above) things begin to go nuts. First of all the parameter "entry" turns null so an exception is thrown.
  To track the possible problem on my end I've implemented a sort of custom IModelBinder that looks like that:</p>
  
  <pre><code>public class BlogEntryBinder : IModelBinder {
      public ModelBinderResult BindModel(ModelBindingContext bindingContext) {
          ModelBinderResult result = ModelBinders.DefaultBinder.BindModel(bindingContext);
          return result;
      }
  }
  </code></pre>
  
  <p>When I come here using the Unity framework and drill down from bindingContext to HttpRequest I see that the Request.HttpMethod is "POST" and Request.Form is properly filled. When I do the same using Spring.NET the method is "GET" and Request.Form is empty.
  When however I step to my controller action (AddEntry) and drill down to the Request in both situations I see that the Request.HttpMethod and Request.Form have their proper values.</p>
  
  <p>Now the question is how do I fix the version with Spring.NET so that it works just like the one that uses Unity framework?</p>