RealmDigital.Architecture
0.0.5
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet new install RealmDigital.Architecture::0.0.5
This package contains a .NET Template Package you can call from the shell/command line.
The Realm Archicture - .NET Template
Installation
$ dotnet new install RealmDigital.Architecture
Usage
$ dotnet new realm-architecture -o [YOUR_PROJECT_NAME]
Use what you want, delete what you don't
Includes a fully featured application (.NET 7 Web API + Next.js UI)
Technology
- .NET 7
- EF Core 7
- Pomelo MySQL
- MediatR
- Source Generators
- Docker
- NextJS
- Auth0
- Terraform
Preamble
- Write a business operation as a MediatR Query/Command
[Authorize(Roles = nameof(Role.Admin))]
public sealed record GetUsersQuery : IQuery<List<CrudContracts.User>>
{
public sealed class Handler : IQueryHandler<GetUsersQuery, List<CrudContracts.User>>
{
private readonly ApplicationContext _applicationContext;
private readonly IMapper _mapper;
public Handler(ApplicationContext applicationContext, IMapper mapper)
{
_applicationContext = applicationContext;
_mapper = mapper;
}
public async Task<ErrorOr<List<CrudContracts.User>>> Handle(GetUsersQuery query, CancellationToken cancellationToken)
{
var users = await _applicationContext.Users.OrderByDescending(x => x.Id).ToListAsync(cancellationToken);
return _mapper.Map<List<CrudContracts.User>>(users);
}
}
}
Magic happens *
Use the query/mutation in your React (or Vue) application
const getUsersQuery = UsersQueries.useGetUsersQuery()
if (getUsersQuery.isError) return <div>Failed to load</div>
if (getUsersQuery.isLoading) return <div>Loading...</div>
return (
<ul>
{users.map(user => (
<li>{user.name}
))}
</ul>
)
- Profit?!?!
* The magic is 3 parts
- Source generators automatically create Web API Controllers for each Query/Command - automatically, on build
- Nswag generates an OpenAPI specificiation document for these controllers - automatically, on build
- A .NET console application generates an Axios based TypeScript API client along with TanStack Query queries & mutations - manually, by running:
$ cd application/tools/[Application.Name].CodeGen.Console
$ dotnet run
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.