Space – A High-Performance, Compile-Time, Mediator Alternative for .NET

image

Introduction: Why We Need “Space”

In the modern .NET ecosystem, the Mediator pattern has become a standard for keeping API architectures clean and loosely coupled. However, the industry standard libraries often rely on Runtime Reflection—scanning your entire application at startup to connect requests to handlers.

While effective, this approach comes with a “tax”: slower startup times and higher memory usage.

Enter Space. Created by Salih Cantekin, Space is a next-generation mediator library that shifts the heavy lifting from Run Time to Compile Time.

How It Works: The “Source Generator” Magic

Unlike traditional libraries that guess where your handlers are while the app is running, Space uses Roslyn Source Generators.

When you build your project, Space analyzes your code and automatically generates the “glue” code needed to connect your Requests to your Handlers.

  • Zero Reflection: No scanning assemblies at runtime.
  • Compile-Time Safety: If you are missing a handler, the compiler will let you know immediately, not when the app crashes in production.
  • Memory Efficiency: Built using ValueTask, Space allows for low-allocation, high-performance execution.

Watch and Learn: Deep Dive with the Creator

For developers who prefer visual learning or want to hear the philosophy behind the architecture, the creator has a dedicated YouTube channel discussing the project’s evolution and implementation details.

📺 Recommended Watch:Salih Can Tekin’s YouTube Channel

Check out the videos specifically titled regarding “Space” to see live coding sessions and performance comparisons.

Project Structure & Features

Based on the documentation (/docs), Space is not just a simple message passer. It includes robust features required for enterprise applications:

  • Pipelines: Similar to middleware, you can wrap logic (like Logging or Validation) around your handlers easily.
  • Notifications: Broadcast events to multiple subscribers at once.
  • Modules: A flexible system to organize dependencies (e.g., Space.Modules.InMemoryCache).

Get Involved: How to Contribute

Space is an open-source project, and community contributions are the lifeblood of its growth. If you are a .NET developer looking to contribute to a high-performance library, here is how you can help:

1. Where to Start

  • The Repository: github.com/salihcantekin/Space
  • The Documentation: Before writing code, read the content in the docs/ folder to understand the current architecture regarding Handlers and Pipelines.

2. Contribution Ideas

If you want to contribute but don’t know where to start, consider these areas:

  • Unit Tests: High-performance libraries require rigorous testing. Adding tests for edge cases is always valuable.
  • Documentation: Improving the .md files in the docs folder or adding a “Getting Started” guide for beginners.
  • Benchmarks: Create a benchmark project comparing Space vs. MediatR in different scenarios (High CPU, High Memory, etc.) to showcase the performance gains.

3. The Workflow

  1. Fork the repository on GitHub.
  2. Clone it to your local machine.
  3. Create a new Branch for your feature or fix.
  4. Submit a Pull Request (PR) with a clear description of what you changed and why.

Conclusion

Space represents a shift towards “Zero-Overhead” architecture in .NET. By utilizing the compiler to do the work, we get the cleanliness of the Mediator pattern without the performance cost.

Ready to try it? Visit the GitHub Repo and give it a star! ⭐

Scroll to Top