Skip to content

iknowcodesoup/mediatr-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stargate MediatR Example

This repository contains a full-stack application composed of a .NET API and a Next.js frontend.

NOTE - What's missing?

  • Middleware for global action/command handling
  • Pre-processors for entity / behavior validation
  • Controller attriute for entity exists / hash-check for if-match
  • Contract / abstraction versioning via factory
  • better test implementation (AI created)
  • better logging (AI created)
  • proper placement for XSS validation (AI added)
  • more than smoke testing
  • more robust or capable UI example

Table of Contents

Development

Prerequisites

Before you begin, ensure you have the following installed:

Getting Started

To get the entire application up and running quickly using Docker:

  1. Navigate to the src directory:
    cd src
  2. Build and run the Docker containers:
    docker-compose up --build
    This will start both the frontend and the API services.

The frontend will typically be available at http://localhost:3000 and the API at http://localhost:5000 (or as configured in docker-compose.yml).

Frontend

The frontend is a Next.js application.

Location: src/frontend

To run the frontend independently (without Docker):

  1. Navigate to the frontend directory:
    cd src/frontend
  2. Install dependencies:
    npm install
  3. Run the development server:
    npm run dev
    The frontend will be available at http://localhost:3000.

API

The API is a .NET 8.0 application.

Location: src/Stargate.Api

To run the API independently (without Docker):

  1. Navigate to the API directory:
    cd src/Stargate.Api
  2. Restore dependencies:
    dotnet restore
  3. Run the application:
    dotnet run
    The API will be available at http://localhost:5000 (or as configured in Properties/launchSettings.json).

Deployment

Deployment instructions will vary based on the target environment. For Docker-based deployments, the docker-compose.yml can serve as a starting point. Further configuration might be needed for production environments (e.g., reverse proxies, environment variables for database connections, etc.).

Testing

Running Tests

Unit and integration tests for the .NET projects are located in the src/Stargate.Tests directory.

To run all tests for the .NET projects:

dotnet test src/Stargate.Tests

Coverage Reporting

Test coverage reports are generated during the test run. After running tests, coverage results can usually be found within the TestResults or coveragereport directories under src/Stargate.Tests.

To generate a coverage report, you might need a tool like ReportGenerator or coverlet. For example, using coverlet and ReportGenerator:

  1. Install coverlet.collector in your test project:
    dotnet add src/Stargate.Tests package coverlet.collector
  2. Run tests with coverage:
    dotnet test src/Stargate.Tests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
  3. Install ReportGenerator global tool:
    dotnet tool install -g dotnet-reportgenerator-globaltool
  4. Generate HTML report (adjust paths as necessary):
    reportgenerator -reports:"src/Stargate.Tests/coverage.opencover.xml" -targetdir:"src/Stargate.Tests/coveragereport" -reporttypes:Html
    Open src/Stargate.Tests/coveragereport/index.html to view the report.

Docker Commands

Here are some common Docker commands useful for this project:

  • Build and run all services:
    docker-compose up --build
  • Start services in detached mode:
    docker-compose up -d
  • Stop and remove containers, networks, and volumes:
    docker-compose down
  • View logs for all services:
    docker-compose logs -f
  • View logs for a specific service (e.g., frontend):
    docker-compose logs -f frontend
  • Execute a command inside a running service container (e.g., bash in frontend):
    docker-compose exec frontend bash
  • List all running containers:
    docker ps

About

An example of using MediatR. Single-contract focused w/o versioning/factory or pre/post-processors.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors