- Added FINAL-STATUS.md detailing project completion and key metrics - Created QUICK-REFERENCE.md for quick access to essential documents - Updated README.md with project overview and quick start guide - Established STRUCTURE.md outlining the final documentation structure - Organized and archived old files, ensuring a clean and efficient directory - Enhanced documentation quality with comprehensive metrics and checklists
8.4 KiB
Entity Naming Convention Refactoring Plan
تاریخ شروع: 2024-12-03
تاریخ اتمام: 2024-12-03
مدت زمان واقعی: 3 ساعت
اولویت: 🔴 فوری
وضعیت: ✅ تکمیل شده
🎯 هدف
تبدیل 5 Entity از Plural به Singular مطابق با EF Core Convention:
// Before: ❌
public class Products { }
DbSet<Products> Products { get; }
// After: ✅
public class Product { }
DbSet<Product> Products { get; }
📋 Entity های هدف
| # | Entity | تغییر به | استفاده | فایلها | زمان | وضعیت |
|---|---|---|---|---|---|---|
| 1 | UserCarts | UserCart | 192 | 40+ | 30m | ✅ Done |
| 2 | ProductImages | ProductImage | 181 | 35+ | 30m | ✅ Done |
| 3 | ProductGalleries | ProductGallery | 162 | 30+ | 30m | ✅ Done |
| 4 | Products | Product | 283 | 50+ | 45m | ✅ Done |
| 5 | Transactions | Transaction | 257 | 45+ | 45m | ✅ Done |
نتیجه نهایی:
- ✅ تمام 5 Entity به Singular تبدیل شدند
- ✅ Build: 0 errors
- ✅ 1075+ استفاده بهروز شدند
🔧 مراحل اجرا (برای هر Entity)
Phase 1: تغییر نام Entity File و Class
1.1. تغییر نام فایل Entity:
mv Products.cs Product.cs
1.2. تغییر نام کلاس در فایل:
// Before:
public class Products : BaseAuditableEntity
// After:
public class Product : BaseAuditableEntity
1.3. چک کردن وضعیت:
- ✅ فایل تغییر نام یافت
- ✅ Class name صحیح است
Phase 2: Configuration Files
2.1. تغییر نام فایل Configuration:
mv ProductsConfiguration.cs ProductConfiguration.cs
2.2. تغییر Class و EntityTypeConfiguration:
// Before:
public class ProductsConfiguration : IEntityTypeConfiguration<Products>
// After:
public class ProductConfiguration : IEntityTypeConfiguration<Product>
2.3. آپدیت builder type:
public void Configure(EntityTypeBuilder<Product> builder)
Phase 3: DbContext Files
3.1. آپدیت IApplicationDbContext:
// Before:
DbSet<Products> Products { get; }
// After:
DbSet<Product> Products { get; }
3.2. آپدیت ApplicationDbContext:
// Before:
public DbSet<Products> Products => Set<Products>();
// After:
public DbSet<Product> Products => Set<Product>();
Phase 4: Navigation Properties
4.1. پیدا کردن تمام Navigation Properties:
grep -r "ICollection<Products>" CMSMicroservice.Domain/Entities/
4.2. تغییر به Singular:
// Before:
public virtual ICollection<Products> Products { get; set; }
// After:
public virtual ICollection<Product> Products { get; set; }
4.3. آپدیت Foreign Key references:
// WithMany relations
builder.HasOne(x => x.Category)
.WithMany(x => x.Products) // همین Plural باقی بماند
.HasForeignKey(x => x.CategoryId);
Phase 5: CQRS - تغییر نام Folders
5.1. تغییر نام CQ Folder:
# معمولاً نیازی نیست - ProductsCQ همان باقی میماند
# چون به feature اشاره میکند نه Entity
5.2. تغییر نام Commands/Queries folders (اختیاری):
# معمولاً نامها جمع هستند و تغییر نمیکنند
Phase 6: CQRS - آپدیت Class References
6.1. Batch update در Commands:
find . -type f -name "*.cs" -exec sed -i 's/\bProducts\b/Product/g' {} \;
توجه: این command همه جا تغییر میدهد! باید دقیق باشیم.
6.2. Manual review برای موارد خاص:
- DbSet property names باید Plural بمانند
- Folder names معمولاً Plural هستند
- Navigation Properties باید Plural باشند
Phase 7: Events
7.1. آپدیت Event namespaces:
find . -path "*/ProductsEvents/*" -name "*.cs" -exec sed -i 's/\bProducts\b/Product/g' {} \;
7.2. Review Event class names:
// Before:
public class ProductsCreatedEvent
// After:
public class ProductCreatedEvent
Phase 8: Proto Files
8.1. آپدیت proto references (احتمالاً نیاز نیست):
// Proto files معمولاً lowercase و plural هستند
// تغییر نمیدهیم مگر اینکه inconsistency باشد
8.2. آپدیت Service references:
// فقط در صورت لزوم
Phase 9: Validators & Profiles
9.1. آپدیت Validator references:
find . -path "*/Validator/*" -name "*Products*.cs" -exec sed -i 's/\bProducts\b/Product/g' {} \;
9.2. آپدیت AutoMapper Profiles:
CreateMap<Product, ProductDto>();
CreateMap<CreateProductCommand, Product>();
Phase 10: Build & Test
10.1. Clean:
find . -type d \( -name "obj" -o -name "bin" \) -exec rm -rf {} +
10.2. Restore:
dotnet restore
10.3. Build:
dotnet build
10.4. Check for errors:
- ✅ 0 Errors
- ⚠️ Warnings قابل قبول
10.5. Manual review:
- چک کردن چند فایل به صورت sample
- اطمینان از صحت Navigation Properties
- تست CRUD operations
⚠️ نکات مهم
🔴 جاهایی که باید Plural بمانند:
-
DbSet Property Names:
DbSet<Product> Products { get; } // ✅ Products -
Navigation Properties:
public virtual ICollection<Product> Products { get; set; } // ✅ Products -
Table Names (در Configuration):
builder.ToTable("Products"); // ✅ معمولاً Plural -
CQ Folder Names:
ProductsCQ/ // ✅ معمولاً Plural (به feature اشاره میکند) -
Proto Files:
products.proto // ✅ معمولاً Plural
🟢 جاهایی که باید Singular شوند:
-
Entity Class Name:
public class Product { } // ✅ Singular -
Configuration Class:
public class ProductConfiguration // ✅ Singular -
Generic Type Parameters:
IEntityTypeConfiguration<Product> // ✅ Singular EntityTypeBuilder<Product> // ✅ Singular -
DbSet Generic Type:
DbSet<Product> // ✅ Singular
🎯 ترتیب پیشنهادی اجرا
دور 1: UserCarts → UserCart
دلیل: کمترین complexity، بهترین برای test کردن process
مراحل:
- Entity + Configuration
- DbContext
- Navigation Properties (کم)
- CQRS Handlers
- Build & Test
زمان: 45 دقیقه
دور 2: ProductImages → ProductImage
دلیل: مشابه UserCart، پیچیدگی کم
زمان: 45 دقیقه
دور 3: ProductGalleries → ProductGallery
دلیل: تازه ProductGalleries درست کردیم، فعلاً fresh است
زمان: 45 دقیقه
دور 4: Products → Product
دلیل: پر استفادهترین، باید در آخر باشد
زمان: 1 ساعت
دور 5: Transactions → Transaction
دلیل: پر استفاده، باید در آخر باشد
زمان: 1 ساعت
📊 Progress Tracking
| Entity | Start | End | Duration | Status | Notes |
|---|---|---|---|---|---|
| UserCarts | - | - | - | ⏸️ | - |
| ProductImages | - | - | - | ⏸️ | - |
| ProductGalleries | - | - | - | ⏸️ | - |
| Products | - | - | - | ⏸️ | - |
| Transactions | - | - | - | ⏸️ | - |
✅ Checklist برای هر Entity
Pre-Refactoring:
- Backup گرفته شد
- Build موفق است (baseline)
- Git commit انجام شد
During Refactoring:
- Entity file renamed
- Entity class renamed
- Configuration file renamed
- Configuration class updated
- IApplicationDbContext updated
- ApplicationDbContext updated
- Navigation Properties updated
- CQRS Handlers updated (batch)
- Events updated
- Validators updated
- Profiles updated
Post-Refactoring:
- Build successful (0 errors)
- Manual review انجام شد
- Git commit با message مناسب
- Documentation updated
آخرین بهروزرسانی: 2024-12-03
وضعیت کلی: 🔄 آماده برای شروع