-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ef core unit of work version 7.0.0 (#28)
* ef core unit of work version 7.0.0 * changed the .net version to 7.0.x in the github actions files
- Loading branch information
Showing
16 changed files
with
132 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.406", | ||
"rollForward": "latestFeature" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.OpenApi.Models; | ||
|
||
namespace EFCoreDataAccess.API.Configurations | ||
{ | ||
public static class Api | ||
{ | ||
public static void AddApi(this IServiceCollection services) | ||
{ | ||
services.AddControllers(). | ||
AddJsonOptions(opt => | ||
{ | ||
opt.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase; | ||
opt.JsonSerializerOptions.WriteIndented = true; | ||
opt.JsonSerializerOptions.MaxDepth = 10; | ||
opt.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles; | ||
opt.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; | ||
opt.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); | ||
}); | ||
|
||
services.AddSwaggerGen(c => | ||
{ | ||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "EFCoreDataAccess.API", Version = "v1" }); | ||
}); | ||
} | ||
|
||
public static void ConfigureApi(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "EFCoreDataAccess.API v1")); | ||
} | ||
|
||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Sample/EFCoreDataAccess.API/Configurations/Database.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using EFCoreDataAccess.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using EFCoreUnitOfWork.Extensions; | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Builder; | ||
using System; | ||
|
||
namespace EFCoreDataAccess.API.Configurations | ||
{ | ||
public static class Database | ||
{ | ||
public static void AddDatabase(this IServiceCollection services) | ||
{ | ||
var connectionString = @"Server=localhost;Database=EFCoreUnitOfWork;Uid=root;Pwd=123456;"; | ||
|
||
// Register DbContext into DI container | ||
// It can use SQL Server, PostgreSQL instead of MySQL | ||
services.AddDbContext<EmployeeDbContext>(options => | ||
options.UseMySql(connectionString, serverVersion: ServerVersion.AutoDetect(connectionString)) | ||
.LogTo(msg => Debug.WriteLine(msg), LogLevel.Error)); | ||
|
||
// Add unit of work into DI container. | ||
// This is an exetensions from the EfCoreUnitOfWork package | ||
services.AddUnitOfWork<EmployeeDbContext>(); | ||
} | ||
|
||
public static void ConfigureDatabase(IApplicationBuilder app) | ||
{ | ||
RunMigrate(app.ApplicationServices); | ||
} | ||
|
||
private static void RunMigrate(IServiceProvider serviceProvider) | ||
{ | ||
var dbContext = serviceProvider.CreateScope().ServiceProvider.GetService<EmployeeDbContext>(); | ||
dbContext.Database.Migrate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
using EFCoreDataAccess.API; | ||
using EFCoreDataAccess.API.Configurations; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
var startup = new Startup(builder.Configuration); | ||
|
||
startup.ConfigureServices(builder.Services); | ||
builder.Services.AddApi(); | ||
builder.Services.AddDatabase(); | ||
|
||
var app = builder.Build(); | ||
|
||
startup.Configure(app, app.Environment); | ||
Api.ConfigureApi(app, app.Environment); | ||
Database.ConfigureDatabase(app); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
src/Sample/EFCoreDataAccess.Data/EFCoreDataAccess.Data.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Sample/EFCoreDataAccess.Models/EFCoreDataAccess.Models.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters