I'm using a custom route in my mvc application that inherits from RouteBase.
In my global.asax I register the route like this:
routes.MapPageRoute("PageRoute", ObjectFactory.GetInstance<IRepository>());
In the GetRouteData method I use my repository to fetch the correct page and then I put that in the RouteValueDictionary like this:
RouteData.DataTokens["CurrentPage"] = _repository.Get("some criteria");
When I update a page in for instance my Update action on my HomeController that looks like this:
public HomeController(IRepository repository) : base(repository) {
_repository = repository;
}
public virtual ActionResult Update([Bind(Prefix = "CurrentPage")] Home item)
{
var item = _repository.Get("some criteria")
UpdateModel(item, "CurrentPage");
_repository.Update(item);
return RedirectToRoute( new { item } );
}
... I end up in the GetRouteData method again and when I fetch the correct page with my repository I get the old page and not the one I updated? My Update method looks like this:
public void Update(Item page) {
using (var transaction = _session.BeginTransaction()) {
_session.SaveOrUpdate(page);
transaction.Commit();
}
}
So does anyone know why this is the case? Is my custom route class a singleton or static so i have an old instance of my repository but then I think my FNH session would be closed? Or maybe it's my update method that is wrong?