Zooper.Squid
2.0.0
dotnet add package Zooper.Squid --version 2.0.0
NuGet\Install-Package Zooper.Squid -Version 2.0.0
<PackageReference Include="Zooper.Squid" Version="2.0.0" />
<PackageVersion Include="Zooper.Squid" Version="2.0.0" />
<PackageReference Include="Zooper.Squid" />
paket add Zooper.Squid --version 2.0.0
#r "nuget: Zooper.Squid, 2.0.0"
#:package Zooper.Squid@2.0.0
#addin nuget:?package=Zooper.Squid&version=2.0.0
#tool nuget:?package=Zooper.Squid&version=2.0.0
Zooper.Squid
<img src="icon.png" alt="Zooper.Squid Logo" width="120" align="right"/>
Zooper.Squid is a lightweight .NET library that simplifies the creation of modular ASP.NET Core applications. It provides a clean and intuitive way to organize your application into independent, reusable modules that can be easily configured and composed.
Key Features
- Modular Architecture: Break down your application into independent, focused modules
- Separation of Concerns: Distinct service and middleware module interfaces
- Explicit Middleware Ordering: Full control over middleware pipeline execution order
- Easy Configuration: Simple and intuitive module registration and configuration
- Dependency Injection: Automatic registration of service modules in your DI container
- Flexible Composition: Mix and match modules to build your application
- Minimal Dependencies: Only depends on ASP.NET Core
- Type-safe: Leverages C#'s type system for robust module definitions
- Testable: Designed with testability in mind from the ground up
Installation
dotnet add package Zooper.Squid
Quick Start
Here's a basic example of creating a modular ASP.NET Core application with Zooper.Squid:
// Define your service module
public class UserServiceModule : IServiceModule
{
public void ConfigureServices(WebApplicationBuilder builder)
{
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
}
}
// Define your middleware module
public class UserMiddlewareModule : IMiddlewareModule
{
public void ConfigureMiddleware(WebApplication app)
{
app.MapControllers();
}
}
// Register modules in your Program.cs
var builder = WebApplication.CreateBuilder(args);
// Register your service modules
builder.AddServiceModules(
typeof(UserServiceModule),
typeof(AuthenticationServiceModule)
);
var app = builder.Build();
// Configure middleware pipeline with explicit ordering
app.ConfigureMiddlewarePipeline()
.AddModule<AuthenticationMiddlewareModule>() // Authentication first
.Add(app => app.UseRouting()) // Then routing
.AddModule<UserMiddlewareModule>() // Then user endpoints
.Build();
app.Run();
Core Concepts
Service Modules
Service modules handle dependency injection configuration and are completely separate from middleware concerns:
public class AuthenticationServiceModule : IServiceModule
{
public void ConfigureServices(WebApplicationBuilder builder)
{
builder.Services.AddAuthentication();
builder.Services.AddAuthorization();
}
}
Middleware Modules
Middleware modules handle the request pipeline configuration:
public class AuthenticationMiddlewareModule : IMiddlewareModule
{
public void ConfigureMiddleware(WebApplication app)
{
app.UseAuthentication();
app.UseAuthorization();
}
}
Explicit Middleware Ordering
The middleware pipeline builder allows you to explicitly control the order of middleware execution:
app.ConfigureMiddlewarePipeline()
.Add(app => app.UseExceptionHandler("/Error")) // Exception handling first
.AddModule<AuthenticationMiddlewareModule>() // Then authentication
.Add(app => app.UseRouting()) // Then routing
.AddModule<ApiMiddlewareModule>() // Then API endpoints
.Build();
Module Registration
Zooper.Squid provides a simple way to register your service modules:
// Register a single service module
builder.AddServiceModules(typeof(AuthenticationServiceModule));
// Register multiple service modules
builder.AddServiceModules(
typeof(AuthenticationServiceModule),
typeof(UserServiceModule),
typeof(LoggingServiceModule)
);
Best Practices
Module Design
- Single Responsibility: Each module should have a single, well-defined purpose
- Separation of Concerns: Keep service configuration separate from middleware configuration
- Clear Boundaries: Define clear boundaries between modules
- Minimal Dependencies: Keep inter-module dependencies to a minimum
Module Implementation
- Service Modules: Use IServiceModule for dependency injection configuration
- Middleware Modules: Use IMiddlewareModule for request pipeline configuration
- Explicit Ordering: Use the middleware pipeline builder for explicit middleware ordering
- Dependencies: Use constructor injection for module dependencies
- Error Handling: Implement proper error handling within modules
Testing
- Module Isolation: Test modules in isolation
- Integration Testing: Test module interactions
- Mock Dependencies: Use mocks for external dependencies
Examples
Check out the examples in the Zooper.Squid/Examples folder for comprehensive examples including:
- Service and middleware module separation
- Authentication service and middleware modules
- Development tools modules
- Explicit middleware pipeline configuration
- Module usage patterns
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- Zooper.Octopus - Hexagonal Architecture implementation
- Zooper.Bee - Fluent workflow framework
- Zooper.Fox - Functional programming primitives
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Hosting.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.