向控制器注入服务时显示错误"不一致的可访问性:参数类型' IProductRepository'比方法产品更容易访问' ProductController.ProductController(IProductRepository)'"
使用的工具/框架:visualstudio_2015,mvc 4.6和unity_Container_4
我对此非常陌生" IoC" ,我想我错过了什么
private IProductRepository _IobjProductRepository;
//error shown in this code part
Injecting Service to Controller shows error -->
public ProductController(IProductRepository Repository)
{ _IobjProductRepository = Repository;}
<--error shown in this code par
t
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IProductRepository,ProductRepository>();
container.RegisterType<IController,ProductController>();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
// MvcUnityContainer.Container = container;
RegisterTypes(container);
return container;
}
public static void RegisterTypes(IUnityContainer container){}
答案 0 :(得分:6)
使您的IProductRepository
成为公共界面。
public interface IProductRepository
{
// your properties & methods
}