0
I’m using Ninject on ASP.Net MVC and trying to implement, but I’m getting a bug:
Error Activating Isessionfactory
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency Isessionfactory into Parameter Session of constructor of type Personrepository
2) Injection of dependency Ipersonrepository into Parameter personsRepository of constructor of type Homecontroller 1) Request for Homecontroller
I’m using Isessionfactory in my repository, I need to bind it?
I’m using Fluent Nhibernate.
My repository:
public class PersonRepository : IPersonRepository
{
private ISession openSession;
private ISessionFactory session;
public PersonRepository(ISessionFactory session)
{
this.openSession = session.OpenSession();
this.session = session;
}
public void CreatePerson(Person person)
{
openSession = NhibernateUtilities.OpenIfClosed(session, openSession);
openSession.SaveOrUpdate(person);
}
}
My controller:
public class HomeController : Controller
{
private readonly IPersonRepository personsRepository;
public HomeController(IPersonRepository personsRepository)
{
this.personsRepository = personsRepository;
}
public ActionResult Index()
{
Person test = new Person()
{
Id = 1,
Name = "teste",
Surname = "teste",
Nickname = "teste",
Age = 25,
Division = "teste",
Email = "teste",
Lane = "teste"
};
personsRepository.CreatePerson(test);
return View();
}
Global.asax:
public class MvcApplication : NinjectHttpApplication
{
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
kernel.Bind<IPersonRepository>().To<PersonRepository>();
return kernel;
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}