Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garcia-tech/garcia
Garcia is a .NET framework
https://github.com/garcia-tech/garcia
c-sharp cqrs ddd domain-driven-design dotnet dotnet-framework framework microservice nuget-package onion-architecture
Last synced: 3 months ago
JSON representation
Garcia is a .NET framework
- Host: GitHub
- URL: https://github.com/garcia-tech/garcia
- Owner: garcia-tech
- License: gpl-3.0
- Created: 2022-12-08T10:59:40.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-11T15:17:24.000Z (6 months ago)
- Last Synced: 2024-10-31T09:42:00.726Z (3 months ago)
- Topics: c-sharp, cqrs, ddd, domain-driven-design, dotnet, dotnet-framework, framework, microservice, nuget-package, onion-architecture
- Language: C#
- Homepage: https://garcia.tech
- Size: 8.64 MB
- Stars: 14
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
#
Garcia is a .Net framework that includes various integrations and utility services. Garcia provides developers to develop fast and powerful web APIs without wasting time with integrations.
## Project Architecture:
The architecture is based on the Onion Architecture, so it can be easily used in DDD projects.
You can take a look at what
Onion Architecture is.## Which Project Layer Contains What ?
The project basically consists of 4 layers. These are :| Layer | Content |
| ------ | ------- |
| Domain: | Contains different types of base entity classes and interfaces.|
| Application: | Contains some application services , infrastructure services contracts and persistence services contracts. |
| Infrastructure: | The layer of integration and infrastructural services. It contains external service registrations, integration adapter services, some settings classes and interfaces, different kind of base controllers.
| Persistence : | The layer of persistency. It contains repository services, db context classes and registration services of them.## Table of Contents:
### Repositories:
- EntityFramework
- MongoDb
- Cassandra
### Message Brokers(AMQP, Pub/Sub):
Garcia has own service bus system. Take a look at here.
You can use the following technologies either with garcia service bus or with their own services.
- RabbitMQ
- Redis Pub/Sub
- Kafka: Coming Soon
### Caching:
- GarciaCache
- Redis
### Search Engines:
- ElasticSearch
### Real Time:
- SignalR
- WebSocket: Coming Soon
### Push Notification:
- Firebase
- Expo Push Notification: Coming Soon
### API Gateway / Service Discovery:
- Ocelot
- Consul
- Eureka (with Ocelot)
### Logging:
- Serilog
- Serilog.Elasticsearch
- Serilog.Graylog
### Email:
- Email.Mandrill
### Localization:
- Localization
### File Upload:
- FileUpload
- FileUpload.AmazonS3
### Marketing:
- Marketing.Mailchimp
## Installation:
Intall Garcia and it's dependencies using NuGet:
NuGet
```ps
> Install-Package Garcia
```
Or:
.NET CLI:
```ps
> dotnet add package Garcia
```
## Quick Start:
Let's create a simple crud service with Entity Framework for a quick start.
### Creating a Project:
```ps
> dotnet new webapi --name QuickStart
```
### Add Garcia To The Project :
```ps
> dotnet add package Garcia
```
### Create Sample Entity:
```cs
using Garcia.Domain;
namespace QuickStart;
public class Sample : Entity
{
public string Name { get; set; }
}
```
### Create SampleDto:
```cs
public class SampleDto
{
public long Id { get; private set; }
public string Name { get; set; }
}
```
### Create SampleController:
```cs
using Garcia.Application.Services;
using Garcia.Infrastructure.Api.Controllers;
using Microsoft.AspNetCore.Mvc;
namespace QuickStart.Controllers;
[ApiController]
public class SampleController : BaseController
// BaseController has 2 generic parameters. These are an Entity and a Dto of the Entity.
{
public SampleController(IBaseService services) : base(services)
{
}
}
```
### Register Services To The Program:
Let's register the EntityFramework, repository services and IBaseService.
Add the following statements to the program class:
```cs
using Garcia.Application;
using Garcia.Application.Contracts.Persistence;
using Garcia.Persistence.EntityFramework;
using QuickStart;
var builder = WebApplication.CreateBuilder(args);
// Other configurations ...
builder.Services
.AddEfCoreInMemory("Sample")
.AddEfCoreRepository();
builder.Services.AddBaseService();
// BaseService also has a 2 generic parameters. These are an Entity and a Dto of the Entity.
```
## Why Not Add An Authentication While You Are At It ?
You need a just few things adding an authentication.
### You Must Create The User:
```cs
using System.ComponentModel.DataAnnotations.Schema;
using Garcia.Domain;
using Garcia.Domain.Identity;
public class User : Entity, IUserEntity // User must be an entity and implemented from IUserEntity
{
public string Username { get; set; }
public string Password { get; set; }
[NotMapped]
public List Roles { get; set; } = new List();
// The role field comes from IUserEntity. If you want, you can customize the Context and define it as the owned entity type.
// If you are using MongoDB or Cassandra for persistence of the User you don't need [NotMapped] attribute.
}
```
### Create UserDto:
```cs
using Garcia.Application.Contracts.Identity;
public class UserDto : IUser
{
public string Id { get; set; }
public string Username { get; set; }
public List Roles { get; set; } = new List();
}
```
### Create AuthenticationController:
```cs
using Garcia.Application.Identity.Services;
using Garcia.Infrastructure.Api.Controllers;
using Microsoft.AspNetCore.Mvc;
namespace QuickStart.Controllers;
[ApiController]
public class AuthenticationController : BaseAuthController
/* BaseAuthController has also 2 generic parameters like a BaseController.
These are a User BaseType is Entity and implemented from IUserEntity,
a UserDto implemented from IUser. */
{
public AuthenticationController(IAuthenticationService service) : base(service)
{
}
}
```
### Register Services To The Program:
Add the following statement to the Program.cs:
```cs
builder.Services.AddAuthenticationService(builder.Configuration);
/* AuthenticationService also has a 2 generic parameters like BaseService.
These are a User BaseType is Entity and implemented from IUserEntity and a UserDto implemented from IUser.*/
```
### Add JwtIssuerOptions To appsettings.json For AuthenticationService:
AuthenticationService uses JwtService for generate and verify a new jwt. JwtService needs JwtIssuerOptions to do this jobs.
```json
"JwtIssuerOptions": {
"Issuer": "garcia",
"Audience": "garcia",
"SecretKey": "2c47231f-9da0-45a6-b6ea-4cf89281b63d",
"ValidFor": 7200
}
```
### Protect Your Apis:
To protect your controller add Authorize attribute top of the controller.
```cs
using Garcia.Application.Services;
using Garcia.Infrastructure.Api.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace QuickStart.Controllers;
[ApiController]
[Authorize(AuthenticationSchemes = "Bearer")]
public class SampleController : BaseController
{
public SampleController(IBaseService services) : base(services)
{
}
}
```
### Configure Your Swagger:
```cs
using Garcia.Infrastructure.Api;
// Other Configurations...
builder.Services.AddSwaggerWithAuthorization();
```
### To Run Your Application:
```ps
> dotnet run
```
You can find complete project in here.
And thats it. Many more different features are waiting for you in here. Welcome to Garcia.