Official C# SDK for Minisource microservices. Provides typed clients for service-to-service communication in .NET applications.
# Via NuGet (when published)
dotnet add package Minisource.Sdk
# Via project reference
dotnet add reference ../csharp-sdk/src/Minisource.Sdk| Service | Client | Status |
|---|---|---|
| Auth | AuthClient |
✅ Available |
| Notifier | NotifierClient |
🚧 Planned |
| Storage | StorageClient |
🚧 Planned |
| Comment | CommentClient |
🚧 Planned |
| Log | LogClient |
🚧 Planned |
| Scheduler | SchedulerClient |
🚧 Planned |
using Minisource.Sdk.Auth;
// Configure services
services.AddMinisourceAuth(options =>
{
options.BaseUrl = "http://auth:9001";
options.ClientId = "my-service";
options.ClientSecret = "secret";
});
// Inject and use
public class MyService
{
private readonly IAuthClient _authClient;
public MyService(IAuthClient authClient)
{
_authClient = authClient;
}
public async Task<User> GetCurrentUser(string token)
{
var claims = await _authClient.ValidateTokenAsync(token);
return new User { Id = claims.UserId, Email = claims.Email };
}
}// Get token for service-to-service calls
var token = await _authClient.GetServiceTokenAsync();
// Use with HttpClient
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);// Validate user token
var result = await _authClient.ValidateTokenAsync(userToken);
if (result.IsValid)
{
var userId = result.Claims.UserId;
var tenantId = result.Claims.TenantId;
var roles = result.Claims.Roles;
}{
"Minisource": {
"Auth": {
"BaseUrl": "http://auth:9001",
"ClientId": "my-service",
"ClientSecret": "your-secret",
"Timeout": "00:00:30",
"AutoRefresh": true
},
"Notifier": {
"BaseUrl": "http://notifier:9002",
"GrpcAddress": "notifier:9003"
},
"Storage": {
"BaseUrl": "http://storage:5004"
}
}
}public void ConfigureServices(IServiceCollection services)
{
// Add all clients
services.AddMinisourceSdk(Configuration);
// Or add individually
services.AddMinisourceAuth(Configuration);
services.AddMinisourceNotifier(Configuration);
services.AddMinisourceStorage(Configuration);
}All clients include automatic retry with exponential backoff:
services.AddMinisourceAuth(options =>
{
options.MaxRetries = 3;
options.RetryDelay = TimeSpan.FromMilliseconds(500);
});Built-in circuit breaker for fault tolerance:
services.AddMinisourceAuth(options =>
{
options.CircuitBreaker = new CircuitBreakerOptions
{
FailureThreshold = 5,
SamplingDuration = TimeSpan.FromSeconds(30),
BreakDuration = TimeSpan.FromSeconds(60)
};
});Clients integrate with Microsoft.Extensions.Logging:
services.AddMinisourceAuth(options =>
{
options.EnableRequestLogging = true;
options.EnableResponseLogging = false; // Don't log sensitive data
});public class TokenClaims
{
public string UserId { get; set; }
public string TenantId { get; set; }
public string Email { get; set; }
public List<string> Roles { get; set; }
public DateTime ExpiresAt { get; set; }
}public class AuthResponse
{
public string AccessToken { get; set; }
public string RefreshToken { get; set; }
public DateTime ExpiresAt { get; set; }
public UserInfo User { get; set; }
}try
{
var result = await _authClient.ValidateTokenAsync(token);
}
catch (AuthenticationException ex)
{
// Token invalid or expired
_logger.LogWarning("Auth failed: {Message}", ex.Message);
}
catch (ServiceUnavailableException ex)
{
// Auth service unreachable
_logger.LogError("Auth service unavailable: {Message}", ex.Message);
}Mock clients are provided for testing:
// In tests
services.AddSingleton<IAuthClient>(new MockAuthClient
{
ValidateResult = new TokenValidationResult
{
IsValid = true,
Claims = new TokenClaims { UserId = "test-user" }
}
});# Build
dotnet build
# Test
dotnet test
# Pack for NuGet
dotnet pack -c ReleaseMinisource.Sdk/
├── Auth/
│ ├── AuthClient.cs
│ ├── AuthOptions.cs
│ ├── IAuthClient.cs
│ └── Models/
├── Notifier/ # Coming soon
├── Storage/ # Coming soon
├── Common/
│ ├── BaseClient.cs
│ └── HttpClientFactory.cs
└── Extensions/
└── ServiceCollectionExtensions.cs
- .NET 10
- Microsoft.Extensions.Http
- Microsoft.Extensions.Options
- Polly (for retry/circuit breaker)
MIT