A REST API with resources representing Guilds, Members, Invites and Memberships, developed in .Net Core including:
- .Net Core 3.1.3;
- Microsoft.EntityFrameworkCore;
- Microsoft.EntityFrameworkCore.SQLite package;
- Authentication and JWT;
- Domain-Driven Design;
- Repositories;
- Unit of Work;
- State Pattern controlling Domain workflows;
- Null Objects;
- FluentValidations;
- MediatR Request/Response Pipelines;
- HATEOAS;
- Cache.
- Distributed Cache (Redis).
This project require installation of some other tools. You need to have GIT to clone this repo, install .Net Core SDK to work with .net cross-platform development environment and use dotnet cli
commands to restore the project and get all packages and dependencies needed properly installed, including EntityFrameworkCore, SQLite and StackExchangeRedis. At last but not least, you will need Redis installed on your system and run it before starts the project execution.
The restore command will provide installations for needed packages.
$ dotnet restore Application
Download, extract somewhere you want and compile Redis with:
$ wget http://download.redis.io/releases/redis-5.0.7.tar.gz
$ tar xzf redis-5.0.7.tar.gz
$ cd redis-5.0.7
$ make
The binaries that are now compiled are available in the src directory. Run Redis with:
$ src/redis-server
-
You can download it directly from Redis official downloads page, compile with Make for Windows similarly to linux installation;
-
Acquire it using Chocolatey and installing Redis-64 package with
choco install redis-64
in Powershell; -
Get a compiled Windows version from dmajkic / redis and set Redis on your environment variables, and use following command to run a basic configuration of redis on prompt like below:
$ redis-server
This will start your Redis local server with default settings.
Configure an entry for your settings in your appsettings.json
. Following there is an example:
{
"RedisCacheSettings": {
"ConnectionString": "localhost,port: 6379,password=your_redis_password!",
"Enabled": true
}
}
To add SQLite to the project you need to register on your dependency injection services through the method ConfigureServices
in the Startup.cs
.
You can do it in many ways. Following there is an example on how to do so:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services
.AddDbContext<YourContext>(options => options.UseSQLite(yourSqlConnectionString));
}
You can use appsettings.json
to set absolute or relative paths for SQLite. If you want to get the absolute path of your application host, you can change default Startup
class constructor adding the IWebHostEnvironment
as parameter like hereinafter:
Startup.cs
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
Environment = env;
}
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; }
And alter the context registration in the ConfigureServices
method of Startup.cs
class. Code below is mounting sql connection using Environment.ContentRootPath
and Configuration
key/value from appsettings.json
.
Startup.cs
var SQLiteAbsolutePathConnectionString = $"Data Source={Environment.ContentRootPath}\\{Configuration["SQLiteSettings:SourceName"]}";
services.AddDbContext<YourContext>(options => options.UseSQLite(SQLiteAbsolutePathConnectionString));
If you are using VS Code, configure your VS Code Debugger with .vscode folder on your project root folder, pres F5
and select .Net Core Launch (web)
as your running target option. It will ask to create a build task, generating a file like following.
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Application/Application.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
You can Compile project with dotnet build Application
and Publish production folder with dotnet publish Application
.
To run, start your Redis server instance and run your project like example below:
Using windows environment variable or accessing your compiled src directory.
$ redis-server
Inside the project directory.
$ dotnet run Application
Feel free to Fork this repo and send a Pull Request with your ideas and improvements, turning this proof of concept any better.
This project was conceived by me, @icarotorres : [email protected], then owner of this repository.