Muonroi.BuildingBlock
1.4.6
See the version list below for details.
dotnet add package Muonroi.BuildingBlock --version 1.4.6
NuGet\Install-Package Muonroi.BuildingBlock -Version 1.4.6
<PackageReference Include="Muonroi.BuildingBlock" Version="1.4.6" />
paket add Muonroi.BuildingBlock --version 1.4.6
#r "nuget: Muonroi.BuildingBlock, 1.4.6"
// Install Muonroi.BuildingBlock as a Cake Addin #addin nuget:?package=Muonroi.BuildingBlock&version=1.4.6 // Install Muonroi.BuildingBlock as a Cake Tool #tool nuget:?package=Muonroi.BuildingBlock&version=1.4.6
API Library with Dependency Injection and Serilog Configuration
Introduction
This library provides entities such as User
, Role
, Permission
, and Language
, and comes with built-in Dependency Injection features, Bearer Token management, JSON handling utilities, string conversion, and localization for multiple languages.
Usage Guide
1. Configuring Program.cs
Here's how to configure your Program.cs
file:
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
Assembly assembly = Assembly.GetExecutingAssembly();
ConfigurationManager configuration = builder.Configuration;
builder.AddAppConfigurations();
builder.AddAutofacConfiguration();
builder.Host.UseSerilog((context, services, loggerConfiguration) =>
{
MSerilogAction.Configure(context, services, loggerConfiguration, false);
});
Log.Information("Starting {ApplicationName} API up", builder.Environment.ApplicationName);
try
{
IServiceCollection services = builder.Services;
// Register services
_ = services.AddApplication(assembly);
_ = services.AddInfrastructure<Program>(configuration);
_ = services.SwaggerConfig(builder.Environment.ApplicationName);
_ = services.AddScopeServices(typeof(<Your Db context>).Assembly);
_ = services.AddValidateBearerToken<MTokenInfo, <Your Enum permission>>(configuration);
_ = services.AddDbContextConfigure<<Your Db context>, <Your Enum permission>>(configuration);
_ = services.AddCors(configuration);
_ = services.AddPermissionFilter<<Your Enum permission>>();
_ = services.ConfigureMapper();
WebApplication app = builder.Build();
_ = app.UseCors("MAllowDomains");
_ = app.UseDefaultMiddleware<<Your Db context>, <Your Enum permission>>();
_ = app.AddLocalization(assembly);
_ = app.UseRouting();
_ = app.UseAuthentication();
_ = app.UseAuthorization();
_ = app.ConfigureEndpoints();
_ = app.MigrateDatabase<<Your Db context>>();
await app.RunAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "Unhandled exception: {Message}", ex.Message);
}
finally
{
Log.Information("Shut down {ApplicationName} complete", builder.Environment.ApplicationName);
await Log.CloseAndFlushAsync();
}
2. Example appsettings.json
Configuration
Here's an example of the appsettings.json
configuration that can be used with this library:
{
"DatabaseConfigs": {
"DbType": "Sqlite",
"ConnectionStrings": {
"SqliteConnectionString": "Your encrypt connection string by serect key",
"MongoDbConnectionString": "Your encrypt connection string by serect key",
"SqlServerConnectionString": "Your encrypt connection string by serect key",
"MySqlConnectionString": "Your encrypt connection string by serect key",
"PostgreSqlConnectionString": "Your encrypt connection string by serect key"
}
},
"ApiKey": "",
"RedisConfigs": {
"Enable": true,
"Host": "Your encrypt by serect key",
"Port": "Your encrypt by serect key",
"Password": "Your encrypt by serect key",
"Expire": 30,
"KeyPrefix": "Your encrypt by serect key",
"AllMethodsEnableCache": false
},
"TokenConfigs": {
"Issuer": "https://exampledomain.com",
"Audience": "https://searchpartners.exampledomain.com",
"SigningKeys": "",
"ExpiryMinutes": 30,
"PublicKey": "-----BEGIN PUBLIC KEY-----\n-----END PUBLIC KEY-----",
"PrivateKey": "-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----"
},
"PaginationConfigs": {
"DefaultPageIndex": 1,
"DefaultPageSize": 10,
"MaxPageSize": 10
},
"ResourceSetting": {
"ResourceName": "Resources.ErrorMessages",
"lang": "vi-VN"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Elasticsearch" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.AspNetCore": "Warning",
"System": "Warning"
}
},
"MAllowDomains": "https://localhost:52182,http://localhost:4200",
"GrpcServices": {
"Services": {
"Your service 1": {
"Uri": "Your service url"
},
"Your service 2": {
"Uri": "Your service url"
},
"Your service 3": {
"Uri": "Your service url"
}
}
},
"ConsulConfigs": {
"ServiceName": "MyService",
"ConsulAddress": "Your service url",
"ServiceAddress": "http://localhost",
"ServicePort": 5000,
"ServiceMetadata": {
"version": "1.0.0",
"environment": "production"
}
},
ApiKey: "Your api key use with grpc",
"SecretKey": "Your serect key use encrypt impotant value",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://localhost:9200",
"autoRegisterTemplate": true,
"indexFormat": "notifications_system-{0:yyyy.MM.dd}",
"inlineFields": true,
"numberOfShards": 2,
"numberOfReplicas": 2,
"autoRegisterTemplateVersion": "ESv7"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "Notifications"
}
},
"ErrorInAverageEveryNTime": 2,
"WarningInAverageEveryNTime": 2
}
Main Components
1. Entities
- User: Manages users.
- Role: Manages user roles.
- Permission: Manages access permissions.
- Language: Manages languages.
2. Dependency Injection
- Integrates necessary services via Dependency Injection (DI) to manage the application lifecycle.
3. Bearer Token
- Manages Bearer Token, authentication, and authorization.
4. JSON Utilities
- Provides utilities for handling JSON, such as converting between strings and objects.
5. Localization
- Supports language localization within the application for various languages.
Contribution
Please submit pull requests or open issues on GitHub to contribute or report bugs for this project.
License
This library is licensed under the MIT License. Please see the LICENSE
file for more details.
Please customize the configuration details (such as ConnectionStrings
, ApiKey
, TokenConfigs
, etc.) according to your application�s requirements.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Asp.Versioning.Mvc (>= 8.1.0)
- Autofac (>= 8.1.1)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- AutoMapper (>= 13.0.1)
- Azure.Identity (>= 1.13.1)
- BCrypt.Net-Core (>= 1.6.0)
- BouncyCastle.NetCore (>= 2.2.1)
- Castle.Core (>= 5.1.1)
- Consul (>= 1.7.14.4)
- Dapper (>= 2.1.35)
- Dapper.Extensions.Caching.Redis (>= 5.1.4)
- Dapper.Extensions.MSSQL (>= 5.1.4)
- Dapper.Extensions.MySQL (>= 5.1.4)
- Dapper.Extensions.NetCore (>= 5.1.4)
- Dapper.Extensions.PostgreSQL (>= 5.1.4)
- Elastic.Serilog.Sinks (>= 8.12.2)
- FluentValidation.AspNetCore (>= 11.3.0)
- Google.Protobuf (>= 3.28.3)
- Grpc.AspNetCore.Server (>= 2.66.0)
- Grpc.Core.Api (>= 2.66.0)
- Grpc.Net.ClientFactory (>= 2.66.0)
- JetBrains.Annotations (>= 2024.3.0)
- MediatR (>= 12.4.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.10)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 8.0.10)
- Microsoft.AspNetCore.OpenApi (>= 8.0.10)
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Data.Sqlite.Core (>= 8.0.10)
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Sqlite.Core (>= 8.0.10)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.1)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.10)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.Http.Resilience (>= 8.10.0)
- Microsoft.IdentityModel.Logging (>= 8.1.2)
- MongoDB.Driver (>= 3.0.0)
- MySql.EntityFrameworkCore (>= 8.0.8)
- NetJSON (>= 1.4.4)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.10)
- Polly (>= 8.4.2)
- Polly.Extensions.Http (>= 3.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.2)
- RestEase (>= 1.6.4)
- Serilog (>= 4.1.0)
- Serilog.AspNetCore (>= 8.0.3)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Formatting.Elasticsearch (>= 10.0.0)
- Serilog.Settings.Configuration (>= 8.0.4)
- Serilog.Sinks.Console (>= 6.0.0)
- Swashbuckle.AspNetCore (>= 6.9.0)
- System.IdentityModel.Tokens.Jwt (>= 8.1.2)
- System.Linq.Async (>= 6.0.1)
- System.Text.Json (>= 8.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muonroi.BuildingBlock:
Package | Downloads |
---|---|
MProjectTemplate.API
This is sample project with MBuildingBlock library |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.4.7 | 84 | 11/30/2024 | |
1.4.6 | 83 | 11/30/2024 | |
1.4.5 | 79 | 11/30/2024 | |
1.4.4 | 84 | 11/26/2024 | |
1.4.3 | 83 | 11/23/2024 | |
1.4.2 | 82 | 11/19/2024 | |
1.4.1 | 84 | 11/16/2024 | |
1.4.0 | 82 | 11/16/2024 | |
1.3.9 | 95 | 11/15/2024 | |
1.3.8 | 83 | 11/15/2024 | |
1.3.7 | 89 | 11/15/2024 | |
1.3.6 | 102 | 11/11/2024 | |
1.3.5 | 94 | 11/11/2024 | |
1.3.4 | 97 | 11/11/2024 | |
1.3.3 | 88 | 11/10/2024 | |
1.3.2 | 84 | 11/10/2024 | |
1.3.1 | 83 | 11/10/2024 | |
1.3.0 | 87 | 11/10/2024 | |
1.2.9 | 89 | 11/8/2024 | |
1.2.8 | 90 | 10/27/2024 | |
1.2.7 | 98 | 10/27/2024 | |
1.2.6 | 100 | 10/27/2024 | |
1.2.5 | 94 | 10/27/2024 | |
1.2.4 | 103 | 10/26/2024 | |
1.2.3 | 93 | 10/25/2024 | |
1.2.2 | 121 | 10/18/2024 | |
1.2.1 | 119 | 10/1/2024 | |
1.2.0 | 135 | 9/8/2024 | |
1.1.9 | 113 | 9/2/2024 | |
1.1.8 | 130 | 9/2/2024 | |
1.1.7 | 122 | 9/1/2024 | |
1.1.6 | 119 | 9/1/2024 | |
1.1.5 | 123 | 9/1/2024 | |
1.1.4 | 116 | 9/1/2024 | |
1.1.3 | 120 | 9/1/2024 | |
1.1.2 | 123 | 9/1/2024 | |
1.1.1 | 115 | 8/31/2024 | |
1.1.0 | 116 | 8/29/2024 | |
1.0.9 | 120 | 8/29/2024 | |
1.0.8 | 156 | 8/27/2024 | |
1.0.7 | 143 | 8/26/2024 | |
1.0.6 | 122 | 8/26/2024 | |
1.0.5 | 145 | 8/25/2024 | |
1.0.4 | 142 | 8/25/2024 | |
1.0.3 | 148 | 8/25/2024 | |
1.0.2 | 145 | 8/25/2024 | |
1.0.1 | 141 | 8/25/2024 | |
1.0.0 | 244 | 8/25/2024 |
This library will help you whenever you create a new project without needing much configuration, as everything is already set up, from bearer tokens to authentication, and more.