Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve singleton in Bind<T>().ToMethod

What is Ninject 3 equivalent of this code:

Bind<ISession>().ToMethod(ctx => ctx.Kernel.Get<INHibernateSessionFactoryBuilder>()
            .GetSessionFactory()
            .OpenSession())
            .Using<OnePerRequestBehavior>();

I know that I can use InRequestScope instead of Using<OnePerRequestBehavior> but how to replace ctx.Kernel.Get<INHibernateSessionFactoryBuilder>? (INHibernateSessionFactoryBuilder is a singleton)

like image 225
user1068352 Avatar asked Dec 07 '12 14:12

user1068352


1 Answers

Ok, just to clarify - since this is in a Module, you can still access ctx.Kernel.Get<T> but you need to add a using Ninject; to the module too as Kernel.Get<T> is exposed as an extension method.

like image 86
Trevor Pilley Avatar answered Sep 22 '22 10:09

Trevor Pilley