I am using NHibernate and ninject in ASP.Net MVC, using this page as a guide . One thing, I think, is strange in this code (halfway down the page)
public class RepositoryModule : NinjectModule
{
public override void Load()
{
const string connectionString = @"Server=localhost; Port=3306; Database=trucktracker; Uid=root; Pwd='your_own_password';";
NHibernateHelper helper = new NHibernateHelper(connectionString);
Bind<ISessionFactory>().ToConstant(helper.SessionFactory).InSingletonScope();
Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
Bind<ISession>().ToProvider(new SessionProvider()).InRequestScope();
Bind<IIntKeyedRepository<Truck>>().To<Repository<Truck>>().InRequestScope();
}
}
It seems strange to me that you need this line for each model:
Bind<IIntKeyedRepository<Truck>>().To<Repository<Truck>>().InRequestScope();
If I have 100 different tables (and therefore models), do I really need to add this row for every class that I have? Isn't there a better way so I can just declare this once and use inheritance to pass to Type in my controller?
source
share