开发者

Repository is Nothing but added in the container later (correctly) (using Unity, Repositories) in ASP.Net MVC 3

I have a "MenuService", which uses an "MenuRepository".

When the MenuService is created, it loads correctly with the MenuRepository. Then it wants to save it in the UnityControllerFactory, but the MenuRepository in the MenuService is Nothing then (it wasn't before).

Very strange.

Does anyone has an idea why this is happening?

Some additional info: I'm using the Unity and Repository pattern. The problem happens with a partial view (for a menu), which i have included in the "HomeController", it could be relevant information, so i included this, just in case:

Function Menu() As ActionResult
    Return PartialView("~\Views/Shared/_Menu.vbhtml", _MenuService.GetAllMenuItems)
End Function

Also, my partial "menu" view is like this: ~/_Menu.vbhtml

@ModelType IEnumerable(Of FacturatieMVCv2.Domain.Slave.MenuItem)

@*<div id="myslidemenu" class="jqueryslidemenu">*@
<ul>

@For Each Item In Model.开发者_StackOverflow社区Where(Function(el) IsNothing(el.HasHigherMenuItem))
@<li> @Html.ActionLink(Item.Naam,Item.Action,Item.Controller)
  <ul>
@For Each SubItem In Model.Where(Function(el) el.HasHigherMenuItem.MenuItemID.Equals(Item.MenuItemID))
      @<li>
            @Html.ActionLink(SubItem.Naam,SubItem.Action,SubItem.Controller)
      </li>
    Next
      </ul>                               
</li>
Next
</ul> 

And i'm calling the partial view with:

@Html.Action("Menu","Home")


You need to setup your IoC before your application starts and you need to get your service from IoC.

This article will help you a lot.

I this case repository dependencies in the service will be resolved by IoC (Unity)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜