ProfileService 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ProfileService --version 1.2.0
                    
NuGet\Install-Package ProfileService -Version 1.2.0
                    
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="ProfileService" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProfileService" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="ProfileService" />
                    
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 ProfileService --version 1.2.0
                    
#r "nuget: ProfileService, 1.2.0"
                    
#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 ProfileService@1.2.0
                    
#: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=ProfileService&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=ProfileService&version=1.2.0
                    
Install as a Cake Tool

ProfileLib

A flexible and extensible profile management library for .NET applications with support for multiple database providers and clean architecture patterns.

Features

  • 🎯 Built with Clean Architecture principles
  • 💾 Multiple database provider support (SQL Server, PostgreSQL, MySQL, SQLite)
  • 🔄 Generic repository pattern
  • 🎨 Extensible base classes
  • 🔍 Flexible search criteria
  • ⚡ High-performance database operations
  • 🛡️ Built-in validation
  • 📦 Easy dependency injection setup

Installation

Install the package via NuGet:

dotnet add package ProfileLib

Based on your database provider, also install the relevant package:

# For SQL Server
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

# For PostgreSQL
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

# For MySQL
dotnet add package Pomelo.EntityFrameworkCore.MySql

# For SQLite
dotnet add package Microsoft.EntityFrameworkCore.Sqlite

Quick Start

  1. Create your profile class:
public class CustomerProfile : ProfileBase
{
    public string? CompanyName { get; private set; }
    public string? Department { get; private set; }

    private CustomerProfile() : base() { }

    public static CustomerProfile Create(string name, string email, string? companyName = null)
    {
        return new CustomerProfile
        {
            Name = name,
            Email = email.ToLower(),
            CompanyName = companyName
        };
    }

    public void Update(string? companyName, string? department)
    {
        CompanyName = companyName;
        Department = department;
        UpdateMetadata(null);
    }
}
  1. Create your search criteria:
public class CustomerSearchCriteria : ProfileSearchCriteriaBase
{
    public string? CompanyName { get; set; }
    public string? Department { get; set; }
}
  1. Set up your DbContext:
public class CustomerDbContext : BaseProfileDbContext<CustomerProfile>
{
    public CustomerDbContext(DbContextOptions<CustomerDbContext> options) 
        : base(options)
    {
    }

    protected override void ConfigureProfile(EntityTypeBuilder<CustomerProfile> builder)
    {
        builder.Property(p => p.CompanyName)
            .HasMaxLength(200);

        builder.Property(p => p.Department)
            .HasMaxLength(100);

        builder.HasIndex(p => p.CompanyName);
    }
}
  1. Configure services:
// Program.cs
public void ConfigureServices(IServiceCollection services)
{
    // Using SQL Server
    services.AddProfileServiceWithSqlServer<CustomerProfile, CustomerSearchCriteria,
        CustomerDbContext, CustomerProfileRepository, CustomerProfileService>(
        configuration,
        configuration.GetConnectionString("DefaultConnection")!);

    // Or using PostgreSQL
    services.AddProfileServiceWithPostgreSQL<CustomerProfile, CustomerSearchCriteria,
        CustomerDbContext, CustomerProfileRepository, CustomerProfileService>(
        configuration,
        configuration.GetConnectionString("DefaultConnection")!);

    // Or using SQLite
    services.AddProfileServiceWithSqlite<CustomerProfile, CustomerSearchCriteria,
        CustomerDbContext, CustomerProfileRepository, CustomerProfileService>(
        configuration,
        "Data Source=profiles.db");
}
  1. Configure appsettings.json:
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=Profiles;Trusted_Connection=True;"
  },
  "ProfileService": {
    "MaxPageSize": 100,
    "CacheDuration": "00:30:00",
    "MaxCacheSize": 1000
  }
}

Advanced Usage

Custom Repository Implementation

public class CustomerProfileRepository 
    : BaseProfileRepository<CustomerProfile, CustomerSearchCriteria>
{
    public CustomerProfileRepository(
        BaseProfileDbContext<CustomerProfile> context,
        ILogger<CustomerProfileRepository> logger)
        : base(context, logger)
    {
    }

    public override async Task<IReadOnlyList<CustomerProfile>> SearchAsync(
        CustomerSearchCriteria criteria,
        CancellationToken cancellationToken = default)
    {
        var query = Context.Profiles.AsNoTracking();

        // Apply base filters
        query = ApplyBaseFilters(query, criteria);

        // Apply custom filters
        if (!string.IsNullOrEmpty(criteria.CompanyName))
        {
            query = query.Where(p => p.CompanyName == criteria.CompanyName);
        }

        return await query
            .Take(criteria.PageSize)
            .ToListAsync(cancellationToken);
    }
}

Validation

public class CustomerProfileValidator : AbstractValidator<CustomerProfile>
{
    public CustomerProfileValidator()
    {
        RuleFor(x => x.Name)
            .NotEmpty()
            .MaximumLength(100);

        RuleFor(x => x.Email)
            .NotEmpty()
            .EmailAddress();

        RuleFor(x => x.CompanyName)
            .MaximumLength(200);
    }
}

Available Database Providers

  • SQL Server
  • PostgreSQL
  • MySQL
  • SQLite

Configuration Options

Option Description Default
MaxPageSize Maximum items per page 100
CacheDuration Cache duration 30 minutes
MaxCacheSize Maximum cache entries 1000

Best Practices

  1. Performance:

    • Use appropriate indexes
    • Implement efficient search criteria
    • Consider caching strategies
  2. Extension:

    • Inherit from base classes
    • Override virtual methods
    • Add custom functionality
  3. Database:

    • Use migrations
    • Set appropriate connection timeouts
    • Configure retry policies

Migration Guide

From v1.x to v2.x

// Old way
services.AddProfileService(options => { ... });

// New way
services.AddProfileServiceWithDatabase<TProfile, ...>(
    configuration,
    DatabaseProvider.SQLServer,
    connectionString);

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Credits

Created and maintained by [Your Name/Organization]

Version History

  • 1.0.0 - Initial release
  • 1.1.0 - Added database provider support
  • 1.2.0 - Added caching and validation

ProfileLib

A flexible and extensible profile management library for .NET applications with support for multiple database providers, built with Clean Architecture principles.

Features

  • 🎯 Clean Architecture Design
  • 💾 Multiple Database Provider Support
    • SQL Server
    • PostgreSQL
    • MySQL
    • SQLite
  • 🔄 Generic Repository Pattern
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.7 169 11/24/2024
1.2.6 106 11/23/2024
1.2.5 106 11/17/2024
1.2.2 104 11/16/2024
1.2.1 100 11/16/2024
1.2.0 102 11/16/2024
1.1.0 107 11/13/2024
1.0.1 156 11/13/2024
1.0.0 168 11/12/2024