connection problems using Ninject

42 views
Skip to first unread message

vinny

unread,
Aug 6, 2010, 11:24:21 AM8/6/10
to NoRM mongodb
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!

vinny

unread,
Aug 10, 2010, 11:08:33 AM8/10/10
to NoRM mongodb
I get this error too often now, I don't know if it comes from Ninject
or NoRM, I'm probably missing something important here, please help
me! I don't want to go back to Fluent NHibernate with MySQL...

"Connection timeout trying to get connection from connection pool"

On 6 août, 11:24, vinny <webmes...@spektrummedia.com> wrote:
> 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 problemhttp://groups.google.com/group/norm-mongodb/browse_thread/thread/b7f7...

Andrew Theken

unread,
Aug 10, 2010, 12:08:42 PM8/10/10
to vinny, NoRM mongodb

typically, this is because you're not disposing the IMongo instance, which returns your connection to the pool.

//Andrew Theken

> --
> You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
> To post to this group, send email to norm-m...@googlegroups.com.
> To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.
>

vinny

unread,
Aug 11, 2010, 9:22:56 AM8/11/10
to NoRM mongodb
If I add throw new NotImplementedException(); in the Dispose() method
of my MongoRepositoryBase class it does not get call so I guess
Ninject does not handle this for me, If I add

protected override void OnActionExecuted(ActionExecutedContext
filterContext)
{
_recipeRepo.Dispose();
base.OnActionExecuted(filterContext);
}
In my controller it does get call. It seems to be fine, thx!

On 10 août, 12:08, Andrew Theken <athe...@gmail.com> wrote:
> typically, this is because you're not disposing the IMongo instance, which returns your connection to the pool.
>
> //Andrew Theken
>
Reply all
Reply to author
Forward
0 new messages