using Microsoft.Practices.Unity;
..
..
public class ContentsController : BaseController
{
[Dependency]
public IContentService contentService { get; set; }
}
我使用統一給我IContentService的一個實例。然而,只有當我宣佈這是公開的時候它纔會起作用。如果我聲明私人,那麼_cs是空的?我是否必須將公共變量聲明爲在Unity中使用[Dependency]?
是我能得到這個通過聲明其公開工作的唯一途徑?
我可以聲明控制器構造函數中IContentService?如果我這樣做,那麼有人可以給我看最好的語法,以及如何將它連接到一個私有變量?