FractalDataWorks.Services
0.9.5-alpha.1008
dotnet add package FractalDataWorks.Services --version 0.9.5-alpha.1008
NuGet\Install-Package FractalDataWorks.Services -Version 0.9.5-alpha.1008
<PackageReference Include="FractalDataWorks.Services" Version="0.9.5-alpha.1008" />
<PackageVersion Include="FractalDataWorks.Services" Version="0.9.5-alpha.1008" />
<PackageReference Include="FractalDataWorks.Services" />
paket add FractalDataWorks.Services --version 0.9.5-alpha.1008
#r "nuget: FractalDataWorks.Services, 0.9.5-alpha.1008"
#:package FractalDataWorks.Services@0.9.5-alpha.1008
#addin nuget:?package=FractalDataWorks.Services&version=0.9.5-alpha.1008&prerelease
#tool nuget:?package=FractalDataWorks.Services&version=0.9.5-alpha.1008&prerelease
FractalDataWorks.Services
Core service foundation for the FractalDataWorks framework providing comprehensive service-oriented architecture patterns with dependency injection, configuration management, command execution, and Railway-Oriented Programming.
Features
- ServiceBase<TCommand, TConfiguration, TService> - Abstract base class for consistent service implementation
- ServiceFactoryBase<TService, TConfiguration> - Type-safe factory with high-performance instantiation via FastGenericNew
- Configuration Management - Integrated FluentValidation for configuration validation
- Message System - Comprehensive messaging for service operations with source-generated collections
- Structured Logging - High-performance logging with MessageLogging attributes returning IGenericMessage
- Result Pattern - Railway-Oriented Programming with IGenericResult<T>
- Thread Safety - All base classes designed for concurrent usage
Installation
<PackageReference Include="FractalDataWorks.Services" Version="1.0.0" />
Quick Start
1. Define Your Command
using FractalDataWorks.Services.Abstractions.Commands;
public interface IEmailCommand : ICommand
{
string To { get; }
string Subject { get; }
string Body { get; }
}
public class SendEmailCommand : IEmailCommand
{
public string To { get; init; }
public string Subject { get; init; }
public string Body { get; init; }
public string From { get; init; }
public bool IsHtml { get; init; }
}
2. Create Configuration
using FractalDataWorks.Configuration.Abstractions;
using FluentValidation;
public class EmailConfiguration : IGenericConfiguration
{
public string Name { get; set; } = "EmailService";
public string SmtpServer { get; set; }
public int Port { get; set; } = 587;
public bool EnableSsl { get; set; } = true;
public string Username { get; set; }
public string Password { get; set; }
public IGenericResult<ValidationResult> Validate()
{
var validator = new EmailConfigurationValidator();
return GenericResult<ValidationResult>.Success(validator.Validate(this));
}
}
public class EmailConfigurationValidator : AbstractValidator<EmailConfiguration>
{
public EmailConfigurationValidator()
{
RuleFor(x => x.SmtpServer).NotEmpty();
RuleFor(x => x.Port).InclusiveBetween(1, 65535);
}
}
3. Implement Your Service
using FractalDataWorks.Services;
public class EmailService : ServiceBase<IEmailCommand, EmailConfiguration, EmailService>
{
public EmailService(ILogger<EmailService> logger, EmailConfiguration configuration)
: base(logger, configuration)
{
}
public override async Task<IGenericResult> Execute(IEmailCommand command)
{
try
{
if (command is not SendEmailCommand sendCmd)
return GenericResult.Failure("Invalid command type");
// Send email logic here
await SendEmail(sendCmd);
Logger.LogInformation("Email sent to {To}", sendCmd.To);
return GenericResult.Success("Email sent successfully");
}
catch (Exception ex)
{
Logger.LogError(ex, "Failed to send email");
return GenericResult.Failure($"Failed to send email: {ex.Message}");
}
}
public override async Task<IGenericResult<TOut>> Execute<TOut>(IEmailCommand command)
{
// Implement for commands that return values
return GenericResult<TOut>.Failure("This service does not return values");
}
}
4. Create Factory
public class EmailServiceFactory : ServiceFactoryBase<EmailService, EmailConfiguration>
{
private readonly ILogger<EmailService> _serviceLogger;
public EmailServiceFactory(
ILogger<EmailServiceFactory> factoryLogger,
ILogger<EmailService> serviceLogger)
: base(factoryLogger)
{
_serviceLogger = serviceLogger;
}
public override IGenericResult<EmailService> Create(EmailConfiguration configuration)
{
// Validation is handled by base class
// FastGenericNew creates the instance efficiently
return base.Create(configuration);
}
}
5. Register with DI
services.AddScoped<EmailServiceFactory>();
services.AddScoped<EmailService>();
services.AddSingleton(new EmailConfiguration
{
SmtpServer = "smtp.gmail.com",
Port = 587,
EnableSsl = true
});
Key Components
ServiceBase
- Provides common service lifecycle management
- Automatic configuration and command validation
- Structured logging with correlation IDs
- Exception handling and result wrapping
- Performance metrics collection
ServiceFactoryBase
- Type-safe service creation
- Automatic configuration validation via FluentValidation
- Uses FastGenericNew for high-performance instantiation
- Comprehensive error handling and logging
Message System
The library includes comprehensive message types for service operations:
- Factory Messages - Service creation results
- Configuration Messages - Configuration validation messages
- Registration Messages - Service registration messages
- Service Messages - Service operation messages
All messages are source-generated for type safety and consistency.
Logging Infrastructure
ServiceBaseLog- Core service operation loggingServiceFactoryLog- Factory creation loggingServiceProviderBaseLog- Provider operation loggingServiceRegistrationLog- Registration loggingPerformanceMetrics- Performance measurement
Service Lifecycle
- Factory Creation - Factory validates configuration
- Service Instantiation - FastGenericNew creates instance
- Command Execution - Command validated and executed
- Result Wrapping - Success/failure wrapped in IGenericResult
- Logging - Operations logged with structured data
Dependencies
FractalDataWorks.Services.Abstractions- Service interfacesFractalDataWorks.Configuration.Abstractions- Configuration contractsFractalDataWorks.Results- Result pattern implementationFractalDataWorks.Messages- Message infrastructureFractalDataWorks.ServiceTypes- Service type discoveryFractalDataWorks.EnhancedEnums- Type-safe enumerationsFastGenericNew- High-performance instantiationFluentValidation- Configuration validationMicrosoft.Extensions.DependencyInjection.Abstractions- DI integrationMicrosoft.Extensions.Logging.Abstractions- Logging
Best Practices
- Always validate configuration in factory Create methods
- Use structured logging for all operations
- Return Result types instead of throwing exceptions
- Implement proper disposal patterns where needed
- Use CancellationToken for async operations
- Register services with appropriate lifetimes
Advanced Features
Custom Validation
public override IGenericResult<EmailService> Create(EmailConfiguration configuration)
{
var baseResult = base.Create(configuration);
if (baseResult.Error) return baseResult;
// Add custom validation
if (!IsSmtpServerReachable(configuration.SmtpServer))
return GenericResult<EmailService>.Failure("SMTP server unreachable");
return baseResult;
}
Service Registration Extensions
services.AddServiceFactory<EmailService, EmailConfiguration, EmailServiceFactory>(options =>
{
options.Lifetime = ServiceLifetime.Scoped;
options.RegisterFactory = true;
});
Documentation
License
Copyright © FractalDataWorks Electric Cooperative. All rights reserved.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- FluentValidation (>= 12.0.0)
- FractalDataWorks.Collections (>= 0.9.5-alpha.1008)
- FractalDataWorks.Configuration (>= 0.9.5-alpha.1008)
- FractalDataWorks.MessageLogging.Abstractions (>= 0.9.5-alpha.1008)
- FractalDataWorks.Messages (>= 0.9.5-alpha.1008)
- FractalDataWorks.Results (>= 0.9.5-alpha.1008)
- FractalDataWorks.Services.Abstractions (>= 0.9.5-alpha.1008)
- FractalDataWorks.Services.Connections.Abstractions (>= 0.9.5-alpha.1008)
- FractalDataWorks.ServiceTypes (>= 0.9.5-alpha.1008)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0-rc.2.25502.107)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0-rc.2.25502.107)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0-rc.2.25502.107)
- Microsoft.Extensions.Options (>= 10.0.0-rc.2.25502.107)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on FractalDataWorks.Services:
| Package | Downloads |
|---|---|
|
FractalDataWorks.Web.RestEndpoints
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
FractalDataWorks.Services.Data
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
FractalDataWorks.Services.Scheduling
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
FractalDataWorks.Services.Connections.MsSql
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
|
|
FractalDataWorks.Services.SecretManagers
Development tools and utilities for the FractalDataWorks ecosystem. Build: |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.5-alpha.1008 | 101 | 11/25/2025 |
| 0.9.5-alpha.1007 | 104 | 11/25/2025 |
| 0.9.5-alpha.1006 | 121 | 11/25/2025 |
| 0.9.1-alpha.1037 | 108 | 11/25/2025 |
| 0.9.1-alpha.1036 | 103 | 11/25/2025 |
| 0.9.1-alpha.1035 | 102 | 11/25/2025 |
| 0.9.1-alpha.1033 | 107 | 11/25/2025 |
| 0.9.0-alpha.1011.ged0a6c6e98 | 350 | 11/18/2025 |
| 0.9.0-alpha.1010.gecd88aac50 | 346 | 11/18/2025 |
| 0.9.0-alpha.1009.g7f6817e985 | 348 | 11/18/2025 |
| 0.9.0-alpha.1006.gf287016c0c | 345 | 11/18/2025 |
| 0.8.0-alpha.1011 | 344 | 11/18/2025 |
| 0.7.0-alpha.1022 | 145 | 11/3/2025 |
| 0.7.0-alpha.1021 | 144 | 11/3/2025 |
| 0.7.0-alpha.1008 | 114 | 11/2/2025 |
| 0.7.0-alpha.1006 | 139 | 10/30/2025 |
| 0.7.0-alpha.1005 | 136 | 10/30/2025 |
| 0.7.0-alpha.1004 | 137 | 10/30/2025 |
| 0.7.0-alpha.1001 | 140 | 10/29/2025 |
| 0.6.0-alpha.1006 | 133 | 10/29/2025 |
| 0.6.0-alpha.1005 | 130 | 10/28/2025 |
| 0.6.0-alpha.1004 | 128 | 10/28/2025 |