更容易訪問。從下面的代碼中,我一直參考私有IOrderProcessor orderProcessor;來解決此錯誤不一致的可訪問性問題。我已經將私人更改爲公開,但錯誤仍然存在。有人可以幫我嗎?不一致的可訪問性:字段類型'FashionWorldApp.Domain.Abstract.IOrderProcessor'比字段'
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 });
}
}
}
你可以發佈你的IOrderProcessor的定義。我的直覺是它不是一個公共接口。還有什麼是完整的錯誤? – Arijoon