![]() |
VOOZH | about |
dotnet add package CG.Infrastructure.Core --version 3.10.9
NuGet\Install-Package CG.Infrastructure.Core -Version 3.10.9
<PackageReference Include="CG.Infrastructure.Core" Version="3.10.9" />
<PackageVersion Include="CG.Infrastructure.Core" Version="3.10.9" />Directory.Packages.props
<PackageReference Include="CG.Infrastructure.Core" />Project file
paket add CG.Infrastructure.Core --version 3.10.9
#r "nuget: CG.Infrastructure.Core, 3.10.9"
#:package CG.Infrastructure.Core@3.10.9
#addin nuget:?package=CG.Infrastructure.Core&version=3.10.9Install as a Cake Addin
#tool nuget:?package=CG.Infrastructure.Core&version=3.10.9Install as a Cake Tool
A core infrastructure library that provides essential service registration and dependency injection capabilities for .NET applications.
CG.Infrastructure.Core is a foundational library that simplifies service registration and dependency injection in .NET applications. It provides automatic service discovery and registration based on interfaces, making it easier to maintain clean architecture and reduce boilerplate code.
dotnet add package CG.Infrastructure.Core
Or add the following to your .csproj file:
<PackageReference Include="CG.Infrastructure.Core" Version="3.10.8" />
Create services that implement the IService interface:
using Infrastructure.Core.Interfaces;
public class UserService : IService
{
public async Task<User> GetUserAsync(int id)
{
// Implementation
}
}
public class EmailService : IService
{
public async Task SendEmailAsync(string to, string subject, string body)
{
// Implementation
}
}
In your Program.cs or Startup.cs:
using Infrastructure.Core.Extensions;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Register all services that implement IService
builder.Services.RegisterInfraCoreServices();
// Or register services for a specific interface
builder.Services.RegisterServices<IMyCustomInterface>();
var app = builder.Build();
[ApiController]
[Route("[controller]")]
public class UserController : ControllerBase
{
private readonly UserService _userService;
private readonly EmailService _emailService;
public UserController(UserService userService, EmailService emailService)
{
_userService = userService;
_emailService = emailService;
}
[HttpGet("{id}")]
public async Task<ActionResult<User>> GetUser(int id)
{
var user = await _userService.GetUserAsync(id);
return Ok(user);
}
}
Register services for any interface (not just IService):
// Register all services that implement IRepository
builder.Services.RegisterServices<IRepository>();
// Register all services that implement IValidator
builder.Services.RegisterServices<IValidator>();
Enable detailed logging to see which assemblies are being scanned:
builder.Services.RegisterInfraCoreServices(detailed: true);
This will output information about:
Include test assemblies during development:
builder.Services.RegisterInfraCoreServices(
detailed: true,
testAssemblyName: "MyProject.Tests"
);
For generic types, use the non-generic overload:
// This will throw an ArgumentException
// builder.Services.RegisterServices<IRepository<>>();
// Use this instead
builder.Services.RegisterServices(typeof(IRepository<>));
The library provides utilities for assembly-related operations, particularly useful for reflection-based scenarios:
using Infrastructure.Core.Utilities;
// Check if an assembly should be skipped during reflection operations
var shouldSkip = AssemblyUtilities.ShouldSkipAssembly(assembly);
// This is useful when scanning assemblies for types, views, or view models
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (AssemblyUtilities.ShouldSkipAssembly(assembly))
continue;
// Process assembly types...
}
The ShouldSkipAssembly method filters out problematic assemblies that commonly cause issues during reflection operations, such as:
The library uses reflection and assembly scanning to automatically discover services:
All services are registered with Scoped lifetime by default, which means:
This library is part of the CG Infrastructure suite. For contributions, please follow the established patterns and ensure all tests pass.
This project is licensed under the terms specified in the LICENSE file.
3.10.8: Current stable release
3.10.7: Previous release
For issues, questions, or contributions, please refer to the project repository or contact the maintainers.
| 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 5 NuGet packages that depend on CG.Infrastructure.Core:
| Package | Downloads |
|---|---|
|
CG.Infrastructure.Services
Infra Services library with shared services |
|
|
CG.Infrastructure.Data
Infra Data library with dbup and dapper |
|
|
CG.Infrastructure.Logging
Infra Logging library with Serilog setup, extensions and database contexts |
|
|
CG.Infrastructure.Mediator
Infra Mediator library with MediatR setup, extensions and database contexts |
|
|
CG.Platform.Presentation
Platform Presentation library with shared services |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.10.9 | 231 | 4/1/2026 |
| 3.10.8 | 684 | 8/13/2025 |
| 3.10.7 | 368 | 8/10/2025 |
| 3.10.6 | 260 | 8/10/2025 |
| 3.10.5 | 637 | 7/22/2025 |
| 3.10.4 | 444 | 6/18/2025 |
| 3.10.3 | 273 | 6/17/2025 |
| 3.10.2 | 279 | 6/16/2025 |
| 3.10.1 | 405 | 6/3/2025 |
| 3.10.0 | 287 | 6/3/2025 |
| 3.9.0 | 503 | 12/10/2024 |
| 3.0.1 | 602 | 3/19/2024 |
| 3.0.0 | 381 | 2/19/2024 |
| 2.0.0 | 1,103 | 5/15/2023 |
| 1.0.2 | 855 | 6/21/2022 |
| 1.0.1 | 580 | 5/26/2022 |
| 1.0.0 | 4,343 | 5/26/2022 |