ProfileService 1.2.0
See the version list below for details.
dotnet add package ProfileService --version 1.2.0
NuGet\Install-Package ProfileService -Version 1.2.0
<PackageReference Include="ProfileService" Version="1.2.0" />
<PackageVersion Include="ProfileService" Version="1.2.0" />
<PackageReference Include="ProfileService" />
paket add ProfileService --version 1.2.0
#r "nuget: ProfileService, 1.2.0"
#:package ProfileService@1.2.0
#addin nuget:?package=ProfileService&version=1.2.0
#tool nuget:?package=ProfileService&version=1.2.0
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
- 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);
}
}
- Create your search criteria:
public class CustomerSearchCriteria : ProfileSearchCriteriaBase
{
public string? CompanyName { get; set; }
public string? Department { get; set; }
}
- 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);
}
}
- 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");
}
- 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
Performance:
- Use appropriate indexes
- Implement efficient search criteria
- Consider caching strategies
Extension:
- Inherit from base classes
- Override virtual methods
- Add custom functionality
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
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- 📫 Email: support@example.com
- 🐛 Issues: GitHub Issues
- 📚 Wiki: Documentation
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 | Versions 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. |
-
net8.0
- FluentValidation (>= 11.9.0)
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.0-beta.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.