ASP.NET MVC 3 Application using Ninject, Entity Framework 4 Code-First CTP 5, Patterns

后端 未结 2 1195
温柔的废话
温柔的废话 2021-01-30 07:35

I\'ve tried to build some base project with above technologies. I wanted maximum flexibility and testability so I tried to use patterns along the way to make this as a base for

2条回答
  •  抹茶落季
    2021-01-30 08:10

    Eww. This one was sneaky. Actually i don't know ninject much so i couldnt figure it out right away.

    I found the solution for the SECOND question which was related to the error by finding that ninject actually shoot two instance of the DatabaseFactory, one for the repository and one for the unit of work. Actually, the error was not the problem. It was an internal error in the object database but its normal i think since im using Entity Framework.

    The real problem was that Ninject was binding two different instance of IDatabaseFactory which lead to 2 connection open.

    The review was added to the first set in _reviewRepostory which was using the first instance of the Database.

    When calling commit on the unit of work.. it saved nothing due to the fact that the review wasnt on this database instance. In fact, the unit of work called the databasefactory which lead to creating a new instance since ninject sent a new instance of it.

    To fix it simply use :

     Bind().To().InSingletonScope();
    

    instead of

    Bind().To();
    

    And now all the system work correctly!

    Now, would love some answers regarding the first question which was if there anything wrong with my current code ? Ive applied patterns correctly ? Any suggestions or recommendation that would lead me in the right direction ?

提交回复
热议问题