Good night everyone, this is my first project using Ninject and MVC , i`m trying to implement but im getting this error:

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

Estou utilizando ISessionFactory no meu repositório, eu preciso dar bind nele?

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);
    }

}

I`m using Fluent Nhibernate, thanks !

Related posts

Recent Viewed