LinKit.Core
1.1.0
dotnet add package LinKit.Core --version 1.1.0
NuGet\Install-Package LinKit.Core -Version 1.1.0
<PackageReference Include="LinKit.Core" Version="1.1.0" />
<PackageVersion Include="LinKit.Core" Version="1.1.0" />
<PackageReference Include="LinKit.Core" />
paket add LinKit.Core --version 1.1.0
#r "nuget: LinKit.Core, 1.1.0"
#:package LinKit.Core@1.1.0
#addin nuget:?package=LinKit.Core&version=1.1.0
#tool nuget:?package=LinKit.Core&version=1.1.0
LinKit.Core
LinKit.Core is a high-performance, modular toolkit for .NET, providing source-generated helpers for CQRS, Dependency Injection, Minimal API Endpoints, Mapping, Messaging, and gRPC. LinKit eliminates boilerplate, maximizes runtime performance, and is fully compatible with NativeAOT and trimming.
Why LinKit?
Most .NET libraries rely on runtime reflection, which is slow, memory-intensive, and incompatible with NativeAOT. LinKit uses C# Source Generators to analyze your code and generate optimized, boilerplate-free C# at compile time, linking your application's components together.
Key Benefits:
- 🚀 Zero Reflection: No runtime scanning or reflection.
- ⚡ Fast Startup: No assembly scanning.
- 🗑️ AOT & Trimming Safe: Works with Blazor, MAUI, NativeAOT.
- ✍️ Clean API: Intent-driven, explicit, and easy to use.
- 🤖 Automated Boilerplate: For DI, API endpoints, gRPC, messaging, and mapping.
LinKit Ecosystem
Package | Description | NuGet |
---|---|---|
LinKit.Core |
Required. Interfaces, attributes, and source generator. | NuGet |
LinKit.Grpc |
gRPC server/client codegen for CQRS requests. | NuGet |
LinKit.Messaging.RabbitMQ |
RabbitMQ implementation for Messaging Kit. | NuGet |
LinKit.Messaging.Kafka |
Kafka implementation for Messaging Kit. | NuGet |
Installation
dotnet add package LinKit.Core
Add other packages as needed:
dotnet add package LinKit.Grpc
dotnet add package LinKit.Messaging.RabbitMQ
Kits Overview
1. CQRS Kit
A source-generated Mediator for the CQRS pattern.
- Define Requests: Implement
ICommand
,ICommand<TResult>
, orIQuery<TResult>
. - Create Handlers: Implement the handler and mark with
[CqrsHandler]
. - Register:
builder.Services.AddLinKitCqrs();
public class GetUserQuery : IQuery<UserDto>
{
public int Id { get; set; }
}
[CqrsHandler]
public class GetUserHandler : IQueryHandler<GetUserQuery, UserDto>
{
public Task<UserDto> Handle(GetUserQuery query, CancellationToken cancellationToken) { ... }
}
Usage:
builder.Services.AddLinKitCqrs();
var user = await mediator.QueryAsync(new GetUserQuery { Id = 1 });
2. Dependency Injection Kit
Attribute-based, source-generated DI registration.
- Mark Services:
[RegisterService(Lifetime.Scoped)]
on your class. - Register:
builder.Services.AddLinKitDependency();
[RegisterService(Lifetime.Scoped)]
public class MyService : IMyService { ... }
Usage:
builder.Services.AddLinKitDependency();
3. Endpoints Kit (Minimal APIs)
Source-generates Minimal API endpoints from CQRS requests.
- Decorate Requests:
[ApiEndpoint]
on your command/query. - Property Binding: Use
[FromRoute]
,[FromQuery]
, etc. - Register:
app.MapGeneratedEndpoints();
[ApiEndpoint(ApiMethod.GET, "users/{Id}")]
public class GetUserQuery : IQuery<UserDto>
{
[FromRoute] public int Id { get; set; }
}
Usage:
app.MapGeneratedEndpoints();
4. Mapping Kit
A reflection-free, source-generated object mapper.
- Create Mapper Context:
[MapperContext]
partial class implementingIMappingConfigurator
. - Configure Mappings: Use
builder.CreateMap<TSrc, TDest>()
and.ForMember(...)
. - No DI Required: Just use the generated extension methods.
[MapperContext]
public partial class AppMapperContext : IMappingConfigurator
{
public void Configure(IMappingBuilder builder)
{
builder.CreateMap<User, UserDto>()
.ForMember(dest => dest.Name, src => src.UserName);
}
}
Usage:
var dto = userEntity.ToUserDto();
var dtos = userEntities.ToUserDtoList();
Mapping Conventions:
- Explicit
.ForMember()
config - Name matching (case-insensitive)
[JsonPropertyName]
/[JsonProperty]
attribute matching
5. Messaging Kit
Source-generated publisher/consumer for message brokers (RabbitMQ, Kafka).
- Mark Messages:
[Message]
on your event/command. - Write Handlers:
[CqrsHandler]
for the message. - Register:
builder.Services.AddLinKitMessaging();
and the broker package.
[Message("user-events", RoutingKey = "user.created", QueueName = "email-service-queue")]
public record UserCreatedEvent(int UserId, string Email);
[CqrsHandler]
public class UserCreatedHandler : ICommandHandler<UserCreatedEvent> { ... }
Publisher:
builder.Services.AddLinKitMessaging();
builder.Services.AddLinKitRabbitMQ(configuration);
// await publisher.PublishAsync(new UserCreatedEvent(...));
Consumer:
builder.Services.AddLinKitCqrs();
builder.Services.AddLinKitMessaging();
builder.Services.AddLinKitRabbitMQ(configuration);
6. gRPC Kit (via LinKit.Grpc)
Source-generates gRPC server and client code for CQRS requests.
Server:
[GrpcEndpoint(typeof(MyServiceBase), "MethodName")]
on CQRS request.- Handler:
[CqrsHandler]
- Register:
builder.Services.AddLinKitGrpcServer();
andapp.MapGrpcService<LinKitMyService>();
[GrpcEndpoint(typeof(UserService.UserServiceBase), "GetUserById")]
public class GetUserQuery : IQuery<UserDto> { ... }
Client:
[GrpcClient(typeof(MyServiceClient), "MethodNameAsync")]
on CQRS request.- Register:
builder.Services.AddLinKitGrpcClient();
andIGrpcChannelProvider
.
[GrpcClient(typeof(UserService.UserClient), "GetUserByIdAsync")]
public class GetUserQuery : IQuery<UserDto> { ... }
Usage:
var user = await mediator.QueryAsync(new GetUserQuery { Id = 1 });
AOT & Trimming
LinKit is fully compatible with NativeAOT and trimming. For best results, use System.Text.Json
source generation for DTOs and messages.
Advanced Configuration
- All
AddLinKit...()
methods are additive and can be combined. - No manual registration of handlers or mappings is needed.
- For custom mapping, use the Mapping Kit.
- For custom gRPC channel, implement
IGrpcChannelProvider
.
Contributing
Contributions, issues, and feature requests are welcome!
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
NuGet packages (3)
Showing the top 3 NuGet packages that depend on LinKit.Core:
Package | Downloads |
---|---|
LinKit.Grpc
gRPC server/client code generation for CQRS requests in LinKit. High-performance, source-generated, AOT/Trimming safe. |
|
LinKit.Messaging.Kafka
Apache Kafka implementation for LinKit.Messaging abstractions. |
|
LinKit.Messaging.RabbitMQ
RabbitMQ implementation for LinKit.Messaging abstractions. |
GitHub repositories
This package is not used by any popular GitHub repositories.