FractalDataWorks.Services 0.9.5-alpha.1008

This is a prerelease version of FractalDataWorks.Services.
dotnet add package FractalDataWorks.Services --version 0.9.5-alpha.1008
                    
NuGet\Install-Package FractalDataWorks.Services -Version 0.9.5-alpha.1008
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FractalDataWorks.Services" Version="0.9.5-alpha.1008" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FractalDataWorks.Services" Version="0.9.5-alpha.1008" />
                    
Directory.Packages.props
<PackageReference Include="FractalDataWorks.Services" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FractalDataWorks.Services --version 0.9.5-alpha.1008
                    
#r "nuget: FractalDataWorks.Services, 0.9.5-alpha.1008"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FractalDataWorks.Services@0.9.5-alpha.1008
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FractalDataWorks.Services&version=0.9.5-alpha.1008&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FractalDataWorks.Services&version=0.9.5-alpha.1008&prerelease
                    
Install as a Cake Tool

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 logging
  • ServiceFactoryLog - Factory creation logging
  • ServiceProviderBaseLog - Provider operation logging
  • ServiceRegistrationLog - Registration logging
  • PerformanceMetrics - Performance measurement

Service Lifecycle

  1. Factory Creation - Factory validates configuration
  2. Service Instantiation - FastGenericNew creates instance
  3. Command Execution - Command validated and executed
  4. Result Wrapping - Success/failure wrapped in IGenericResult
  5. Logging - Operations logged with structured data

Dependencies

  • FractalDataWorks.Services.Abstractions - Service interfaces
  • FractalDataWorks.Configuration.Abstractions - Configuration contracts
  • FractalDataWorks.Results - Result pattern implementation
  • FractalDataWorks.Messages - Message infrastructure
  • FractalDataWorks.ServiceTypes - Service type discovery
  • FractalDataWorks.EnhancedEnums - Type-safe enumerations
  • FastGenericNew - High-performance instantiation
  • FluentValidation - Configuration validation
  • Microsoft.Extensions.DependencyInjection.Abstractions - DI integration
  • Microsoft.Extensions.Logging.Abstractions - Logging

Best Practices

  1. Always validate configuration in factory Create methods
  2. Use structured logging for all operations
  3. Return Result types instead of throwing exceptions
  4. Implement proper disposal patterns where needed
  5. Use CancellationToken for async operations
  6. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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