0
有沒有辦法做一個綁定,會說「當注入IService到區域內的任何控制器管理員注入此實例」?用Ninject注入區域內的控制器
我們在Admin中有許多可能使用相同服務的控制器。我們可以爲每個控制器編寫綁定,但隨後可能會引入另一個控制器使用相同的服務,並且開發人員忘記專門爲管理員(使用不同於其他區域或區域之外的一組服務實現)進行連線。
// this is the default
kernel.Bind<ICategorizationRepository<DirectoryCategory>>().To<CachedJsonCategorizationProvider<DirectoryCategory>>().InRequestScope();
// Admin bindings use noncaching repositories
kernel.Bind<ICategorizationRepository<DirectoryCategory>>().To<JsonCategorizationProvider<DirectoryCategory>>().WhenInjectedInto<Areas.Admin.Controllers.DirectoryCategorizationController>().InRequestScope();
kernel.Bind<ICategorizationRepository<DirectoryCategory>>().To<JsonCategorizationProvider<DirectoryCategory>>().WhenInjectedInto<Areas.Admin.Controllers.DirectoryEntryController>().InRequestScope();
// .. new controller that uses ICategorizationRepo might be created but the developer forgets to wire it up to the non caching repository - so the default one will be used, which is undesirable
我想說:注入管理區域內的任何時候,用這個...