Setup
Get the solution building, connected to a database, and running locally.
Project Files
The solution lives under eCommerceMVCCore/ and is composed of five projects:
| Project | Purpose |
|---|---|
eCommerce.Web | The ASP.NET Core MVC application — controllers, views, areas, Program.cs, wwwroot |
eCommerce.Data | eCommerceContext (EF Core DbContext) and migrations |
eCommerce.Services | Business/data-access logic |
eCommerce.Entities | EF entity classes and DTOs |
eCommerce.Shared | Cross-cutting helpers, extensions, attributes, constants |
Prerequisites
- .NET 10 SDK
- SQL Server, or SQL Server LocalDB (used by default)
Build & run
cd eCommerceMVCCore
dotnet build eCommerceMVCCore.slnx
dotnet run --project eCommerce.Web
The app listens on http://localhost:5209 (and https://localhost:7156) per eCommerce.Web/Properties/launchSettings.json, in the Development environment.
Publish for production
dotnet publish eCommerce.Web -c Release -o ./publish
The app and its database can also run entirely in Docker, with no local .NET SDK or database install — see Docker.
Database Setup
The connection string lives in eCommerce.Web/appsettings.json:
"ConnectionStrings": {
"eCommerceConnectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=ecommercedb_core;Integrated Security=True;TrustServerCertificate=True;"
}
On first run, Program.cs automatically:
- Applies all pending EF Core migrations (
context.Database.Migrate()) — creates the database if it doesn’t exist yet - Seeds roles (
Administrator,Moderator,User), a default admin account, languages, and default site configuration (eCommerceDbSeeder)
You don’t need to run any SQL yourself for normal development — just point the connection string at an empty database and start the app. If you’d rather create the schema by hand, or want realistic sample data, see Demo Data.
Database Providers
The database engine is a configuration choice, not a code change: set DatabaseProvider in appsettings.json to one of SqlServer (default), MySql, PostgreSql, or Sqlite, and point eCommerceConnectionString at a connection string in that provider’s format.
| Provider | DatabaseProvider | Example connection string |
|---|---|---|
| SQL Server / LocalDB | SqlServer | Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ecommercedb_core;Integrated Security=True;TrustServerCertificate=True; |
| MySQL | MySql | Server=localhost;Database=ecommercedb_core;User=root;Password=yourpassword; |
| PostgreSQL | PostgreSql | Host=localhost;Database=ecommercedb_core;Username=postgres;Password=yourpassword; |
| SQLite | Sqlite | Data Source=ecommercedb_core.sqlite3 |
Each provider has its own EF Core migration history under eCommerce.Data/Migrations/<Provider> (SQL Server’s is the original, unprefixed Migrations/ folder) and its own eCommerceContext subclass under eCommerce.Data/Providers/ — see Code Structure for why a migration scaffolded for one provider can’t simply be replayed against another (it bakes in that provider’s column types and auto-increment annotations). All four are wired up centrally in DatabaseProviderConfigurator.
MySQL support is built on Oracle’s MySql.EntityFrameworkCore package rather than the more commonly used community Pomelo provider, because Pomelo doesn’t yet have a release compatible with EF Core 10.
Adding support for another EF Core provider follows the same pattern: a subclass in Providers/, a design-time factory in Providers/DesignTime/ for scaffolding, a case in DatabaseProviderConfigurator and the DatabaseProvider enum, and a scaffolded InitialCreate migration under its own Migrations/<Provider> folder.
Default Roles & Users
Three roles are seeded: Administrator, Moderator, User. A single seeded account has all three:
| Field | Value |
|---|---|
| Username | adm_use |
adm_use@domain.com | |
| Password | adm_use123 |
This account and password are seeded in source (eCommerceDbSeeder.cs) purely for local development. Change the password (or create a new admin and disable this one) before deploying anywhere reachable by the public — see the Go-Live Checklist below.
New storefront registrations (via /register or the API) are assigned the User role only. Roles and per-user role assignment are managed from the dashboard — see Users, Roles & Comments.
Go-Live Checklist
Things worth checking before you point this at real traffic:
- JWT signing key —
Jwt:Keyinappsettings.jsonships as the placeholderCHANGE_THIS_TO_A_LONG_RANDOM_SECRET_BEFORE_PRODUCTION_USE_.... Replace it with a real random secret (and keep it out of source control for production — use environment variables, Azure App Configuration/Key Vault, or a user-secrets equivalent). - Connection string — point
eCommerceConnectionStringat your real database, not LocalDB. Environmentconfiguration key — a custom setting ("Environment": "LIVE"inappsettings.json, read viaConfigurationsHelper.Environment) is separate from ASP.NET Core’s ownASPNETCORE_ENVIRONMENT. When it’sLIVE, the API area’s exception filter swallows unhandled exceptions into a generic 500 response instead of leaking stack traces — correct for production, but it also means API bugs won’t show up in request/response bodies, only in server-side logs (they aren’t even written to the standard ASP.NET Core diagnostic log — see API → Response Envelope).- SendGrid —
SendGrid_APIKeydefaults to empty. Until it’s set (Dashboard → Configurations), account-registration, forgot-password, and order-notification emails will silently fail to send rather than error out loudly. - Admin email — set
AdminEmailAddressso order-placed notifications actually reach someone. - HTTPS — the app calls
UseHsts()/UseHttpsRedirection()outside Development; make sure your deployment target terminates TLS somewhere. - Error pages — unhandled exceptions and 404s are served from static
wwwroot/500.html/404.html, not a Razor view. Customize those files directly if you want your own branding.