![]() |
VOOZH | about |
dotnet add package AstreCode.Backend.Shared.Domain --version 10.0.0.4
NuGet\Install-Package AstreCode.Backend.Shared.Domain -Version 10.0.0.4
<PackageReference Include="AstreCode.Backend.Shared.Domain" Version="10.0.0.4" />
<PackageVersion Include="AstreCode.Backend.Shared.Domain" Version="10.0.0.4" />Directory.Packages.props
<PackageReference Include="AstreCode.Backend.Shared.Domain" />Project file
paket add AstreCode.Backend.Shared.Domain --version 10.0.0.4
#r "nuget: AstreCode.Backend.Shared.Domain, 10.0.0.4"
#:package AstreCode.Backend.Shared.Domain@10.0.0.4
#addin nuget:?package=AstreCode.Backend.Shared.Domain&version=10.0.0.4Install as a Cake Addin
#tool nuget:?package=AstreCode.Backend.Shared.Domain&version=10.0.0.4Install as a Cake Tool
Domain layer components for AstreCode microservices.
The AstreCode.Backend.Shared.Domain package provides essential domain layer components for building robust and scalable .NET 8.0 backend services. This package includes domain entities, business rules, validation utilities, and core domain interfaces.
To install this package, use the .NET CLI:
dotnet add package AstreCode.Backend.Shared.Domain
Or via Package Manager Console:
Install-Package AstreCode.Backend.Shared.Domain
using Shared.Domain.Entities;
public class User : FullAuditEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public bool IsActive { get; set; }
}
using Shared.Domain.Entities;
public interface IUserRepository : IBaseRepository<User>
{
Task<User> GetByEmailAsync(string email);
Task<List<User>> GetActiveUsersAsync();
}
public class UserRepository : BaseRepository<User>, IUserRepository
{
public UserRepository(DbContext context) : base(context)
{
}
public async Task<User> GetByEmailAsync(string email)
{
return await GetQueryable()
.FirstOrDefaultAsync(u => u.Email == email);
}
public async Task<List<User>> GetActiveUsersAsync()
{
return await GetQueryable()
.Where(u => u.IsActive)
.ToListAsync();
}
}
using Shared.Domain.Exceptions;
public class UserService
{
public async Task<User> GetUserAsync(Guid userId)
{
var user = await _userRepository.GetByIdAsync(userId);
if (user == null)
{
throw new NotFoundException("User not found");
}
return user;
}
public async Task DeleteUserAsync(Guid userId)
{
if (!_currentUser.HasPermission("Delete:User"))
{
throw new ForbiddenException("Insufficient permissions");
}
var user = await GetUserAsync(userId);
await _userRepository.DeleteAsync(user);
}
}
using Shared.Domain.Validation;
public class UserValidator
{
public void ValidateUser(User user)
{
if (string.IsNullOrEmpty(user.Email))
{
throw new UserFriendlyException("Email is required");
}
if (!Check.IsValidEmail(user.Email))
{
throw new UserFriendlyException("Invalid email format");
}
if (!string.IsNullOrEmpty(user.PhoneNumber))
{
if (!Check.SaudiPhoneNumber(user.PhoneNumber))
{
throw new UserFriendlyException("Invalid Saudi phone number");
}
}
}
}
using Shared.Domain.CommonData;
public class UserService
{
private readonly ICurrentUser _currentUser;
public async Task<List<User>> GetUsersAsync()
{
if (!_currentUser.HasPermission("Read:Users"))
{
throw new ForbiddenException("Access denied");
}
// Get users based on current user's tenant
return await _userRepository.GetQueryable()
.Where(u => u.TenantId == _currentUser.TenantId)
.ToListAsync();
}
}
using Shared.Domain.Dtos;
public class UserService
{
public async Task<PaginatedList<User>> GetUsersAsync(PagedInputDto input)
{
var query = _userRepository.GetQueryable();
var totalCount = await query.CountAsync();
var users = await query
.Skip((input.PageNumber - 1) * input.PageSize)
.Take(input.PageSize)
.ToListAsync();
return new PaginatedList<User>(users, totalCount, input.PageNumber, input.PageSize);
}
}
// In your DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Configure base entities
modelBuilder.Entity<User>().HasKey(u => u.Id);
modelBuilder.Entity<User>().Property(u => u.Id).ValueGeneratedOnAdd();
// Configure audit properties
modelBuilder.Entity<User>().Property(u => u.CreatedAt).IsRequired();
modelBuilder.Entity<User>().Property(u => u.ModifiedAt).IsRequired();
}
// In Program.cs
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { "en-US", "ar-SA" };
options.SetDefaultCulture(supportedCultures[0])
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
});
This package depends on the following NuGet packages:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the file for details.
For support and questions, please contact the AstreCode development team.
See for version history and changes.
AstreCode.Backend.Shared.Domain - Version 8.0.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on AstreCode.Backend.Shared.Domain:
| Package | Downloads |
|---|---|
|
AstreCode.Backend.Shared.Application
The shared application project for AstreCode backend |
|
|
AstreCode.Backend.Shared.UnitTest
The shared UnitTest project for AstreCode backend |
This package is not used by any popular GitHub repositories.