可访问性不一致:字段类型' FashionWorldApp.Domain.Abstract.IOrderProcessor'比现场更容易接近'

时间:2016-04-23 17:12:55

标签: c#

从下面的代码中,我通过引用私有IOrderProcessor orderProcessor;来保持此错误不一致的可访问性。我已将私人更改为公开,但错误仍然存​​在。有人可以帮助我吗?

namespace FashionWorldApp.WebUI.Controllers
{
public class CartController : Controller    {
    private IProductRepository repository;
    private IOrderProcessor orderProcessor;

    public CartController(IProductRepository repo, IOrderProcessor proc)
    {
        repository = repo;
        orderProcessor = proc;
    }

    public ViewResult Index(Cart cart, string returnUrl)
    {
        return View(new CartIndexViewModel
        {
            Cart = cart,
            ReturnUrl = returnUrl
        });
    }

    public PartialViewResult Summary(Cart cart)
    {
        return PartialView(cart);
    }

    [HttpPost]
 public ViewResult Checkout(Cart cart, ShippingDetails  shippingDetails)
    {
        if (cart.Lines.Count() == 0)
        {
            ModelState.AddModelError("", "Sorry, your cart is empty!");
        }

        if (ModelState.IsValid)
        {
            orderProcessor.ProcessOrder(cart, shippingDetails);
            cart.Clear();
            return View("Completed");
        }
        else
        {
            return View(shippingDetails);
        }
    }

    public ViewResult Checkout()
    {
        return View(new ShippingDetails());
    }
     public RedirectToRouteResult AddToCart
          (Cart cart, int productId, string returnUrl)
    {
        Product product = repository.Products
            .FirstOrDefault(p => p.ProductID == productId);

        if (product != null)
        {
            cart.AddItem(product, 1);
        }
        return RedirectToAction("Index", new { returnUrl });
    }

 public RedirectToRouteResult RemoveFromCart
         (Cart cart, int productId, string returnUrl)
    {
        Product product = repository.Products
            .FirstOrDefault(p => p.ProductID == productId);

        if (product != null)
        {
            cart.RemoveLine(product);
        }
        return RedirectToAction("Index", new { returnUrl });
    }
}
}

1 个答案:

答案 0 :(得分:0)

将IProductRepository接口更改为public。你有一个公共构造函数接受IProductRepository作为参数,你需要保证外部调用可以看到它。