This demo performs the same product-availability order simulation as the previous two-service microservices demo, but **runs as one ASP.NET Core web application**. Product and Order modules are separate .NET class libraries with a defined interface boundary.
## Open and run in Visual Studio
1. Extract the ZIP.
2. Open `ModularShop.sln` in **Visual Studio 2022** with .NET 8 SDK and ASP.NET and web development workload.
3. Right-click **ModularShop.Web** → **Set as Startup Project**.
4. Build Solution (`Ctrl+Shift+B`).
5. Run the Web project. Open `http://localhost:5003` if it does not launch automatically.
6. Enter **Laptop** (success), **Phone** (failure).
> The port is set to 5003 in `src/ModularShop.Web/Program.cs`. No database or NuGet packages are required.
## Projects and dependencies
```text
ModularShop.Web (ASP.NET Core Razor Pages — single executable)
`ModularShop.Orders` does **not** reference `ModularShop.Products`. It knows only the public interface. The product implementation and repository are `internal`, so other modules cannot call their internals directly.
`ModularShop.Web` is the only runnable application. The class libraries are compiled into it and are NOT separately deployed as services.
6. Result is returned through the same call chain and shown on the page.
## Step-by-step build from scratch (Visual Studio)
1. Create a **Blank Solution** named `ModularShop`.
2. Add **ASP.NET Core Web App (Razor Pages)** named `ModularShop.Web`, targeting **.NET 8**.
3. Add three **Class Library** projects named `ModularShop.Products.Contracts`, `ModularShop.Products`, and `ModularShop.Orders`, all targeting **.NET 8**.
-`ModularShop.Web` → `ModularShop.Products` and `ModularShop.Orders`
5. In the two module project `.csproj` files, add `<FrameworkReference Include="Microsoft.AspNetCore.App" />` in an `<ItemGroup>` to enable use of ASP.NET Core's dependency-injection registration without additional packages.
6. Create the classes/files from the extracted project, keeping namespaces as shown.
7. Register both modules in the Web project's `Program.cs`.
8. Set `ModularShop.Web` as startup project and run.
## Lesson notes
-**Monolith**: one runnable/deployable backend (`ModularShop.Web`).
-**Modular**: code is grouped by business capability into Products and Orders modules, not only global folders such as `Services` and `Repositories`.
-**Encapsulation**: product implementation classes are `internal`, and other modules use the public contract `IProductCatalog`.
-**Layering inside a module**: Products module has a domain-facing product catalog and a repository. Modules and layers describe two different ways of looking at the same software.
-**Communication**: no HTTP between modules; it is ordinary in-process C# method calls. Compare with the earlier microservices version where OrderService used `HttpClient` to call ProductService over HTTP.
-**Data**: demonstration uses an in-memory collection. No actual orders are saved, and product data resets at process restart.
### Student exercise
- Add `Monitor` to the repository's product set and verify it can be ordered.
- Try to access `ProductRepository` directly from the Orders project. Explain why the design prevents it.
- Change `IProductCatalog.IsAvailable` and show the two projects needing the interface change.