Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# entity Repository
I have build my site using entity and repository pattern with ninject injection. My problem is my connections don't seem to get disposed. I have around 30 repositories (one for each table) and I get sql expiration timout preety quick. I can't use the regular using statement because the code recognize only the interface before the injection. (in each controler I have my repositories interface instances which get injected via ninject).
 
I have searched the net but couldn't find a solution that was accurate for me. can anyone please help me? code example:
 
this is in the ninject controller under addBindings():
 
 ninjectKernel.Bind<IMovieRepository>().To<MovieRepository>().InRequestScope();
 
and one of my repositories:
 
public class MovieRepository : IMovieRepository, IDisposable 
        {
         private Entities dataContext = new Entities();
         public System.Data.Entity.DbContext DbContext 
         {
            get { return dataContext ?? (dataContext = new Entities()); } 
         }
         public void Dispose() { dataContext.Dispose(); }
        }
 
and in the Global.asax file:
 
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory() as IControllerFactory);
Posted 21-Apr-12 9:03am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 504
1 Gihan Liyanage 298
2 RyanDev 250
3 Sergey Alexandrovich Kryukov 223
4 Richard Deeming 195
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 21 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100