https://github.com/gpproton/axolotl
A personal shared project library for dotnet
https://github.com/gpproton/axolotl
aspnet-core blazor csharp dotnet dotnet-core maui razor
Last synced: 9 months ago
JSON representation
A personal shared project library for dotnet
- Host: GitHub
- URL: https://github.com/gpproton/axolotl
- Owner: gpproton
- License: mit
- Created: 2023-03-09T20:11:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-15T17:57:37.000Z (over 1 year ago)
- Last Synced: 2025-10-05T16:51:26.610Z (9 months ago)
- Topics: aspnet-core, blazor, csharp, dotnet, dotnet-core, maui, razor
- Language: C#
- Homepage: http://axolotl.godwin.dev/
- Size: 305 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Axolotl
A personal shared library for various types of dotnet project types
NOTE: Issues can be created to improve documentation and fix errors
### Sub-packages
- Axolotl:
- Axolotl.Http:
- Axolotl.EFCore:
- Axolotl.Razor:
# Install
The framework is provided as a set of NuGet packages. In many cases you'll only need the base package, but if you need efcore or razor there are implementation-specific packages available to assist.
To install the minimum requirements:
```
Install-Package Axolotl
```
## Asp.Net Core Samples
### Added required packages
```powershell
Install-Package Axolotl
Install-Package Axolotl.EFCore
Install-Package Axolotl.AspNet
```
### Add sample entity
```csharp
public sealed class Post : AuditableEntity {
public string Title { get; set; } = null!;
public Category Category { get; set; } = null!;
public ICollection Tags { get; set; } = null!;
}
```
### Create your DB context
```csharp
public class ServiceContext : DbContext {
public ServiceContext(DbContextOptions options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder) { }
public virtual DbSet Posts { get; set; } = null!;
}
```
### Create your generic repository and apply DbContext
```csharp
public class GenericRepository : GenericBaseRepository
where TEntity : class, IAggregateRoot, IHasKey
where TKey : notnull {
public GenericRepository(ServiceContext context) : base(context) { }
}
```
### Register your DB context & Unit of work
```csharp
builder.Services.AddDbContext(options => options.UseSqlite());
builder.Services.RegisterUnitOfWork(pooled: false);
```
### Register generic repository & service
```csharp
builder.Services.RegisterGenericRepositories(typeof(GenericRepository<,>));
builder.Services.RegisterGenericServices();
```
### Create optional filter specification
```csharp
public sealed class CategorySpec : Specification {
public CategorySpec(IPageFilter filter) {
var search = filter.Search ?? string.Empty;
var text = search.ToLower().Split(" ").ToList().Select(x => x);
Query.Where(x => x.Title != String.Empty && x.Title.Length > 3 && text.Any(p => EF.Functions.Like(x.Title.ToLower(), $"%" + p + "%")))
.AsNoTracking()
.OrderBy(b => b.Title);
}
}
```
### Create feature/endpoint
```csharp
public class CategoryFeature : GenericFeature {
public override IEndpointRouteBuilder MapEndpoints(IEndpointRouteBuilder endpoints) {
var state = new FeatureState(new List {
new (RouteType.GetAll, typeof(CategorySpec)),
new (RouteType.GetById),
new (RouteType.Create)
});
return SetupGroup(endpoints, state);
}
}
```