Hi,
I am using NoRM with Rob's MVCStarter in my MVC2 web appplication and
I randomlt having connections trouble. I saw this post that might be
the solution for my problem
http://groups.google.com/group/norm-mongodb/browse_thread/thread/b7f7a97f6e5794ed/a9b7a1893899b371
but I'm not quite sure. Since I'm using Ninject, do I need to close my
connection? Does Ninject handle the connection for me or I still need
to dispose it?
This is my global.cs :
internal class SiteModule : NinjectModule
{
public override void Load()
{
Bind<ISession>().To<MongoSession>().InRequestScope();
}
}
public static IKernel Container
{
get
{
if (_container == null)
{
_container = new StandardKernel(new SiteModule());
}
return _container;
}
}
protected override void OnApplicationStarted()
{
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
And here's one sample code for one of my Controller :
[Authorize]
public partial class ProviderController : CMSBaseController
{
private ISession _session;
public ProviderController(ISession session)
{
_session = session;
}
public virtual ActionResult Ajout()
{
ViewData.Model = new Provider();
return View();
}
[HttpPost][ValidateInput(false)]
[ValidateAntiForgeryToken]
public virtual ActionResult Ajout([Bind(Exclude =
"Id")]Provider provider)
{
provider.AdminId = CurrentAdminId;
provider.CreationDate = DateTime.Now;
provider.LastModification = provider.CreationDate;
ViewData.Model = provider;
if (ModelState.IsValid)
{
try
{
_session.Save(provider);
}
catch (RulesException ex)
{
ex.AddModelStateErrors(ModelState, null);
}
}
return ModelState.IsValid ?
RedirectToAction(MVC.Provider.List()) : (ActionResult)View();
}
}
Thanks a lot!