Idevs.Net.CoreLib
0.2.1
dotnet add package Idevs.Net.CoreLib --version 0.2.1
NuGet\Install-Package Idevs.Net.CoreLib -Version 0.2.1
<PackageReference Include="Idevs.Net.CoreLib" Version="0.2.1" />
<PackageVersion Include="Idevs.Net.CoreLib" Version="0.2.1" />
<PackageReference Include="Idevs.Net.CoreLib" />
paket add Idevs.Net.CoreLib --version 0.2.1
#r "nuget: Idevs.Net.CoreLib, 0.2.1"
#:package Idevs.Net.CoreLib@0.2.1
#addin nuget:?package=Idevs.Net.CoreLib&version=0.2.1
#tool nuget:?package=Idevs.Net.CoreLib&version=0.2.1
Idevs.Net.CoreLib
A comprehensive extension library for the Serenity Framework that provides enhanced functionality for data export, PDF generation, UI components, and more.
Features
- 📊 Excel Export: Advanced Excel generation with formatting, themes, and aggregation support
- 📄 PDF Export: HTML-to-PDF conversion using Puppeteer Sharp
- 🎨 UI Components: Extended form controls and formatters for Serenity
- 🔄 Service Registration: Automatic dependency injection with attributes
- 📐 Bootstrap Grid: Enhanced column width controls with Bootstrap 5 support
- 🌍 Localization: Enhanced text localization extensions
Installation
Install via NuGet Package Manager:
dotnet add package Idevs.Net.CoreLib
Or via Package Manager Console:
Install-Package Idevs.Net.CoreLib
Quick Start
1. Service Registration with Autofac (Recommended)
Idevs.Net.CoreLib now uses Autofac as the preferred dependency injection container. Add the following to your Program.cs
:
using Idevs.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Configure Autofac as the service provider and register Idevs services
builder.UseIdevsAutofac();
// Your other service registrations
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Your middleware configuration
app.UseRouting();
app.MapControllers();
app.Run();
1.1. Alternative Service Registration (Legacy)
For projects that cannot use Autofac, you can still use the traditional service collection approach:
// In ConfigureServices method or Program.cs
builder.Services.AddIdevsCorelibServices();
// Note: RegisterServices() is now obsolete and included in AddIdevsCorelibServices()
1.2. Advanced Autofac Configuration
For more advanced scenarios, you can customize the Autofac container:
// With custom container configuration
builder.UseIdevsAutofac(containerBuilder =>
{
// Your custom registrations
containerBuilder.RegisterType<MyCustomService>()
.As<IMyCustomService>()
.InstancePerLifetimeScope();
});
// With additional modules
builder.UseIdevsAutofac(new MyCustomModule(), new AnotherModule());
2. Chrome Setup for PDF Export
Important: For PDF export functionality, you need to download Chrome/Chromium:
// In Program.cs Main method (before starting the application)
public static void Main(string[] args)
{
// Download Chrome if not already present
ChromeHelper.DownloadChrome();
CreateHostBuilder(args).Build().Run();
}
Usage Examples
Excel Export
public class OrderController : ServiceEndpoint
{
private readonly IIdevsExcelExporter _excelExporter;
public OrderController(IIdevsExcelExporter excelExporter)
{
_excelExporter = excelExporter;
}
[HttpPost]
public IActionResult ExportToExcel(ListRequest request)
{
var orders = GetOrders(request); // Your data retrieval logic
// Simple export
var excelBytes = _excelExporter.Export(orders, typeof(OrderColumns));
return IdevsContentResult.Create(
excelBytes,
IdevsContentType.Excel,
"orders.xlsx"
);
}
[HttpPost]
public IActionResult ExportWithHeaders(ListRequest request)
{
var orders = GetOrders(request);
var headers = new[]
{
new ReportHeader { HeaderLine = "Order Report" },
new ReportHeader { HeaderLine = $"Generated: {DateTime.Now:yyyy-MM-dd}" },
new ReportHeader { HeaderLine = "" } // Empty line
};
var excelBytes = _excelExporter.Export(orders, typeof(OrderColumns), headers);
return IdevsContentResult.Create(excelBytes, IdevsContentType.Excel, "order-report.xlsx");
}
}
PDF Export
public class ReportController : ServiceEndpoint
{
private readonly IIdevsPdfExporter _pdfExporter;
private readonly IViewPageRenderer _viewRenderer;
public ReportController(IIdevsPdfExporter pdfExporter, IViewPageRenderer viewRenderer)
{
_pdfExporter = pdfExporter;
_viewRenderer = viewRenderer;
}
[HttpPost]
public async Task<IActionResult> GenerateReport(ReportRequest request)
{
// Render HTML from Razor view
var model = GetReportData(request);
var html = await _viewRenderer.RenderViewAsync("Reports/OrderReport", model);
// Convert to PDF
var pdfBytes = await _pdfExporter.ExportAsync(
html,
"<div style='text-align: center;'>Order Report</div>", // Header
"<div style='text-align: center;'>Page <span class='pageNumber'></span></div>" // Footer
);
return IdevsContentResult.Create(pdfBytes, IdevsContentType.Pdf, "report.pdf");
}
}
UI Components
// Enhanced column attributes
public class OrderColumns
{
[DisplayName("Order ID"), ColumnWidth(ExtraLarge = 2)]
public string OrderId { get; set; }
[DisplayName("Customer"), FullColumnWidth]
public string CustomerName { get; set; }
[DisplayName("Order Date"), DisplayDateFormat, HalfWidth]
public DateTime OrderDate { get; set; }
[DisplayName("Amount"), DisplayNumberFormat("n2")]
public decimal Amount { get; set; }
[DisplayName("Status"), CheckboxFormatter(TrueText = "Completed", FalseText = "Pending")]
public bool IsCompleted { get; set; }
}
Service Registration with Attributes
Idevs.Net.CoreLib supports both legacy attributes and enhanced standard attributes for service registration:
Legacy Attributes (Backward Compatibility)
[ScopedRegistration]
public class OrderService : IOrderService
{
// Your service implementation
}
[SingletonRegiatration]
public class CacheService : ICacheService
{
// Singleton service
}
[TransientRegistration]
public class EmailService : IEmailService
{
// Transient service
}
Standard Attributes (Enhanced Features)
// Basic usage - auto-discovers I{ClassName} interface
[Scoped]
public class OrderService : IOrderService
{
// Scoped service implementation
}
// Explicit service type specification
[Singleton(ServiceType = typeof(ICacheService))]
public class CacheService : ICacheService, IDisposable
{
// Singleton service with explicit interface
}
// Named registrations (Autofac only)
[Transient(ServiceKey = "smtp")]
public class SmtpEmailService : IEmailService
{
// SMTP email implementation
}
[Transient(ServiceKey = "sendgrid")]
public class SendGridEmailService : IEmailService
{
// SendGrid email implementation
}
// Self-registration without interface
[Scoped(AllowSelfRegistration = true)]
public class UtilityService
{
public void DoWork() { }
}
Attribute Comparison
Feature | Legacy Attributes | Standard Attributes |
---|---|---|
Interface Discovery | I{ClassName} only |
I{ClassName} + any interface + self-registration |
Service Keys | Not supported | Supported (Autofac only) |
Explicit Service Type | Not supported | Supported |
Self-registration | Not supported | Supported |
Backward Compatibility | ✅ | ✅ (both work together) |
Static Service Resolution
For scenarios where dependency injection is not feasible (e.g., static methods, legacy code integration), you can use the StaticServiceLocator:
// Initialize in your Program.cs (automatic with Autofac)
var app = builder.Build();
app.UseIdevsStaticServiceLocator(); // Automatically detects Autofac or traditional DI
// Use in static methods or legacy code
public static class LegacyHelper
{
public static void ProcessData()
{
// Resolve services statically
var excelExporter = StaticServiceLocator.Resolve<IIdevsExcelExporter>();
var pdfExporter = StaticServiceLocator.Resolve<IIdevsPdfExporter>();
// Use try resolve for optional services
var optionalService = StaticServiceLocator.TryResolve<IOptionalService>();
if (optionalService != null)
{
// Use the service
}
// Use scoped resolution for per-request services
using var scope = StaticServiceLocator.CreateScope();
var scopedService = scope.ServiceProvider.GetService<IScopedService>();
}
public static void ProcessDataWithCaching()
{
// Cache singleton services for better performance
var cachedService = StaticServiceLocator.ResolveSingleton<IMySingletonService>();
}
}
Important: Use StaticServiceLocator sparingly and prefer proper dependency injection whenever possible.
Configuration Options
Excel Export Customization
// Custom theme
var request = new IdevsExportRequest
{
TableTheme = TableTheme.TableStyleMedium15,
CompanyName = "My Company",
ReportName = "Sales Report",
PageSize = new PageSize(PageSizes.A4, PageOrientations.Landscape)
};
PDF Export Options
// Custom page settings in your CSS
@page {
size: A4;
margin: 1in;
}
// Or use PuppeteerSharp options directly
var pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
MarginOptions = new MarginOptions
{
Top = "1in",
Right = "1in",
Bottom = "1in",
Left = "1in"
},
PreferCSSPageSize = true
};
Troubleshooting
PDF Export Issues
Problem: PDF generation fails with "Chrome not found" error Solution: Ensure Chrome is downloaded:
// Check if Chrome is available
if (!ChromeHelper.IsChromeDownloaded())
{
ChromeHelper.DownloadChrome();
}
Problem: PDF export hangs or times out Solution: Ensure your HTML doesn't have external dependencies that can't be loaded:
<style>
/* Your styles here */
</style>
Excel Export Issues
Problem: Column formatting not applied Solution: Use proper format attributes:
[DisplayNumberFormat("#,##0.00")] // For numbers
[DisplayDateFormat] // For dates (dd/MM/yyyy)
[DisplayPercentage] // For percentages
Problem: Large datasets cause memory issues Solution: Process data in chunks or use streaming:
// Process in smaller batches
const int batchSize = 10000;
for (int i = 0; i < totalRecords; i += batchSize)
{
var batch = GetDataBatch(i, batchSize);
// Process batch
}
Migration Guide
From v0.1.x to v0.2.0 (Current)
Autofac Integration (Recommended)
- Update to Autofac: Replace service collection registration with Autofac:
// Old way (v0.1.x)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddIdevsCorelibServices();
// New way (v0.2.0) - Recommended
var builder = WebApplication.CreateBuilder(args);
builder.UseIdevsAutofac();
- Legacy Support: If you cannot use Autofac, the old way still works:
// Still supported for backward compatibility
builder.Services.AddIdevsCorelibServices();
// Note: RegisterServices() is now obsolete
// builder.Services.RegisterServices(); // Remove this line
Benefits of Autofac Integration
- Better Performance: Autofac provides superior dependency resolution performance
- Advanced Features: Support for decorators, interceptors, and advanced lifetime scopes
- Module System: Organized service registration through modules
- Attribute-Based Registration: Automatic service discovery and registration
From v0.0.x to v0.1.x
- Service Registration: Replace manual service registration with
AddIdevsCorelibServices()
:
// Old way
services.AddScoped<IViewPageRenderer, ViewPageRenderer>();
services.AddScoped<IIdevsPdfExporter, IdevsPdfExporter>();
services.AddScoped<IIdevsExcelExporter, IdevsExcelExporter>();
// New way
services.AddIdevsCorelibServices();
- Chrome Setup: Add Chrome download to startup:
// Add this to Program.cs
ChromeHelper.DownloadChrome();
- Static Service Provider: Migrate to StaticServiceLocator (recommended):
// Old way (still works but obsolete)
StaticServiceProvider.Provider = app.ApplicationServices;
var service = StaticServiceProvider.GetService<IMyService>();
// New way (recommended)
var app = builder.Build();
app.UseIdevsStaticServiceLocator(); // Automatic initialization
var service = StaticServiceLocator.Resolve<IMyService>();
// Or manual initialization
// StaticServiceLocator.Initialize(app.Services);
StaticServiceLocator Benefits
- Autofac Support: Works seamlessly with both Autofac and traditional DI
- Thread Safety: Improved thread-safe operations
- Better Error Handling: More descriptive error messages
- Scoped Resolution: Support for creating service scopes
- Performance: Caching options for singleton services
- Backward Compatibility: Automatic fallback when using StaticServiceProvider
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
- @klomkling - Sarawut Phaekuntod
Changelog
See CHANGELOG.md for a detailed history of changes.
Made with ❤️ for the Serenity Framework community
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
- Ardalis.GuardClauses (>= 5.0.0)
- Autofac (>= 8.1.1)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- Autofac.Extras.AttributeMetadata (>= 6.0.0)
- ClosedXML (>= 0.105.0)
- FastMember (>= 1.5.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.18)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 8.0.18)
- Microsoft.Data.SqlClient (>= 6.0.2)
- PuppeteerSharp (>= 20.2.2)
- Serenity.Net.Services (>= 8.8.6)
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 |
---|---|---|
0.2.1 | 0 | 8/21/2025 |
0.2.0 | 17 | 8/16/2025 |
0.1.0 | 160 | 12/5/2024 |
0.0.92 | 168 | 9/3/2024 |
0.0.91 | 139 | 8/28/2024 |
0.0.90 | 161 | 8/28/2024 |
0.0.89 | 149 | 8/28/2024 |
0.0.88 | 157 | 8/26/2024 |
0.0.87 | 189 | 8/17/2024 |
0.0.86 | 156 | 8/17/2024 |
0.0.85 | 173 | 8/16/2024 |
0.0.84 | 183 | 3/24/2024 |
0.0.83 | 196 | 1/27/2024 |
0.0.82 | 158 | 1/23/2024 |
0.0.81 | 143 | 1/22/2024 |
0.0.80 | 178 | 1/15/2024 |
0.0.79 | 168 | 1/14/2024 |
0.0.78 | 148 | 1/14/2024 |
0.0.77 | 163 | 1/14/2024 |
0.0.76 | 151 | 1/14/2024 |
0.0.75 | 167 | 1/13/2024 |
0.0.74 | 158 | 1/13/2024 |
0.0.73 | 278 | 10/23/2023 |
0.0.72 | 195 | 10/15/2023 |
0.0.71 | 205 | 10/15/2023 |
0.0.70 | 173 | 10/14/2023 |
0.0.69 | 167 | 10/14/2023 |
0.0.68 | 187 | 10/13/2023 |
0.0.67 | 228 | 8/27/2023 |
0.0.66 | 225 | 6/10/2023 |
0.0.65 | 204 | 6/10/2023 |
0.0.64 | 225 | 6/10/2023 |
0.0.63 | 248 | 6/8/2023 |
0.0.62 | 239 | 6/3/2023 |
0.0.61 | 232 | 6/3/2023 |
0.0.60 | 237 | 6/1/2023 |
0.0.59 | 210 | 6/1/2023 |
0.0.58 | 206 | 5/31/2023 |
0.0.57 | 201 | 5/31/2023 |
0.0.56 | 222 | 5/31/2023 |
0.0.55 | 235 | 5/31/2023 |
0.0.54 | 202 | 5/31/2023 |
0.0.53 | 210 | 5/31/2023 |
0.0.52 | 191 | 5/31/2023 |
0.0.51 | 205 | 5/31/2023 |
0.0.50 | 193 | 5/30/2023 |
0.0.49 | 205 | 5/27/2023 |
0.0.48 | 183 | 5/27/2023 |
0.0.47 | 201 | 5/26/2023 |
0.0.46 | 205 | 5/26/2023 |
0.0.45 | 181 | 5/26/2023 |
0.0.44 | 200 | 5/26/2023 |
0.0.43 | 185 | 5/26/2023 |
0.0.42 | 195 | 5/26/2023 |
0.0.41 | 208 | 5/26/2023 |
0.0.40 | 190 | 5/24/2023 |
0.0.39 | 224 | 4/15/2023 |
0.0.38 | 252 | 4/15/2023 |
0.0.37 | 271 | 4/13/2023 |
0.0.36 | 234 | 4/13/2023 |
0.0.35 | 224 | 4/13/2023 |
0.0.34 | 240 | 4/12/2023 |
0.0.33 | 232 | 4/12/2023 |
0.0.32 | 237 | 4/12/2023 |
0.0.31 | 238 | 4/12/2023 |
0.0.30 | 242 | 4/12/2023 |
0.0.29 | 280 | 4/2/2023 |
0.0.28 | 256 | 4/2/2023 |
0.0.27 | 255 | 4/2/2023 |
0.0.26 | 293 | 3/26/2023 |
0.0.25 | 262 | 3/26/2023 |
0.0.24 | 251 | 3/24/2023 |
0.0.23 | 275 | 3/24/2023 |
0.0.22 | 259 | 3/24/2023 |
0.0.21 | 274 | 3/22/2023 |
0.0.20 | 273 | 3/22/2023 |
0.0.19 | 279 | 3/21/2023 |
0.0.18 | 276 | 3/12/2023 |
0.0.17 | 271 | 3/9/2023 |
0.0.16 | 293 | 3/4/2023 |
0.0.15 | 269 | 3/4/2023 |
0.0.14 | 326 | 3/4/2023 |
0.0.13 | 272 | 3/4/2023 |
0.0.12 | 265 | 3/4/2023 |
0.0.11 | 286 | 3/2/2023 |
0.0.10 | 275 | 3/2/2023 |
0.0.9 | 289 | 2/28/2023 |
0.0.8 | 301 | 2/28/2023 |
0.0.7 | 293 | 2/28/2023 |
0.0.6 | 286 | 2/28/2023 |
0.0.5 | 285 | 2/28/2023 |
0.0.4 | 281 | 2/27/2023 |
0.0.3 | 295 | 2/27/2023 |
0.0.2 | 283 | 2/26/2023 |
0.0.1 | 286 | 2/25/2023 |