An open API service indexing awesome lists of open source software.

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

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);
}
}
```