Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
#nullable enable
using Grand.Domain.Orders;
using Grand.Web.AdminShared.Interfaces;
using Microsoft.AspNetCore.Http;
namespace Grand.Web.AdminShared.Services;
/// <summary>
/// Resolves the correct per-host <see cref="IAdminDataScope{CheckoutAttribute}" /> implementation
/// at request time, based on the current request's "area" route value — same fix and same reason
/// as <see cref="RoutedCategoryDataScope"/>: Grand.Web (the combined host) loads Admin and Store
/// together in one DI container, so a plain per-host registration would silently let whichever
/// host's StartupApplication ran last win for every area in that process.
///
/// No Vendor branch: CheckoutAttribute has no Vendor screen at all, so any "Vendor" (or other
/// unrecognized/missing) area value fails closed.
/// </summary>
public class RoutedCheckoutAttributeDataScope(
IHttpContextAccessor httpContextAccessor,
GlobalAdminDataScope<CheckoutAttribute> globalScope,
StoreAdminDataScope<CheckoutAttribute> storeScope) : IAdminDataScope<CheckoutAttribute>
{
private IAdminDataScope<CheckoutAttribute> Resolved
{
get
{
var area = httpContextAccessor.HttpContext?.Request.RouteValues["area"] as string;
return area switch {
"Admin" => globalScope,
"Store" => storeScope,
_ => throw new InvalidOperationException(
$"RoutedCheckoutAttributeDataScope: unrecognized or missing area '{area}'.")
};
}
}
public Task<bool> HasAccess(CheckoutAttribute entity) => Resolved.HasAccess(entity);
public Task<bool> CanView(CheckoutAttribute entity) => Resolved.CanView(entity);
public string? DefaultStoreId => Resolved.DefaultStoreId;
public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;
public bool ShowStoreSelector => Resolved.ShowStoreSelector;
public string? DefaultVendorId => Resolved.DefaultVendorId;
public bool CanFeatureOnHomepage => Resolved.CanFeatureOnHomepage;
}