Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structural Refactoring - .NET 6.0 & SqlServer #45

Merged
merged 20 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ checks:
config:
threshold: 100
exclude_patterns:
- "src/IronHook.PostgreSql/Migrations/"
- "src/IronHook.EntityFrameworkCore.PostgreSql/Migrations/"
- "src/IronHook.EntityFrameworkCore.SqlServer/Migrations/"
- "samples/IronHook.Web/Migrations/"
35 changes: 26 additions & 9 deletions IronHook.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.223
# Visual Studio Version 17
VisualStudioVersion = 17.1.31903.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}"
EndProject
Expand All @@ -13,8 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.Core", "src\IronHo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.EntityFrameworkCore", "src\IronHook.EntityFrameworkCore\IronHook.EntityFrameworkCore.csproj", "{1EE36765-D6E8-452E-B4A2-DC7157EF16D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.PostgreSql", "src\IronHook.PostgreSql\IronHook.PostgreSql.csproj", "{C7DF96DD-4046-425E-895D-295E66741FE6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.Web", "samples\IronHook.Web\IronHook.Web.csproj", "{DFF10173-23A6-4E76-88AE-0E6900236607}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{228129FA-C2BF-4B64-8B5F-E7DC3B6A2CA8}"
Expand All @@ -24,6 +22,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Dockerfile = Dockerfile
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.EntityFrameworkCore.SqlServer", "src\IronHook.EntityFrameworkCore.SqlServer\IronHook.EntityFrameworkCore.SqlServer.csproj", "{19CB6A33-941C-41BC-94A9-5E254F68A787}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.EntityFrameworkCore.PostgreSql", "src\IronHook.EntityFrameworkCore.PostgreSql\IronHook.EntityFrameworkCore.PostgreSql.csproj", "{7DB75589-C32C-42E7-B4B5-E140DB21082A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet6", "dotnet6", "{CA4AC978-0A6F-4B86-B805-DFE2F6904DAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronHook.Web", "samples\dotnet6\IronHook.Web\IronHook.Web.csproj", "{719956BA-2B70-404C-A8CB-F780623F4178}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,23 +44,34 @@ Global
{1EE36765-D6E8-452E-B4A2-DC7157EF16D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EE36765-D6E8-452E-B4A2-DC7157EF16D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EE36765-D6E8-452E-B4A2-DC7157EF16D2}.Release|Any CPU.Build.0 = Release|Any CPU
{C7DF96DD-4046-425E-895D-295E66741FE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7DF96DD-4046-425E-895D-295E66741FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7DF96DD-4046-425E-895D-295E66741FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7DF96DD-4046-425E-895D-295E66741FE6}.Release|Any CPU.Build.0 = Release|Any CPU
{DFF10173-23A6-4E76-88AE-0E6900236607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DFF10173-23A6-4E76-88AE-0E6900236607}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DFF10173-23A6-4E76-88AE-0E6900236607}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFF10173-23A6-4E76-88AE-0E6900236607}.Release|Any CPU.Build.0 = Release|Any CPU
{19CB6A33-941C-41BC-94A9-5E254F68A787}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19CB6A33-941C-41BC-94A9-5E254F68A787}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19CB6A33-941C-41BC-94A9-5E254F68A787}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19CB6A33-941C-41BC-94A9-5E254F68A787}.Release|Any CPU.Build.0 = Release|Any CPU
{7DB75589-C32C-42E7-B4B5-E140DB21082A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DB75589-C32C-42E7-B4B5-E140DB21082A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DB75589-C32C-42E7-B4B5-E140DB21082A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DB75589-C32C-42E7-B4B5-E140DB21082A}.Release|Any CPU.Build.0 = Release|Any CPU
{719956BA-2B70-404C-A8CB-F780623F4178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{719956BA-2B70-404C-A8CB-F780623F4178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{719956BA-2B70-404C-A8CB-F780623F4178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{719956BA-2B70-404C-A8CB-F780623F4178}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{92BA62A2-B3F9-4897-874A-41C4FA78BF47} = {B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}
{1EE36765-D6E8-452E-B4A2-DC7157EF16D2} = {B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}
{C7DF96DD-4046-425E-895D-295E66741FE6} = {B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}
{DFF10173-23A6-4E76-88AE-0E6900236607} = {2550698D-C602-4592-8DEF-C15AF6C6E46F}
{19CB6A33-941C-41BC-94A9-5E254F68A787} = {B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}
{7DB75589-C32C-42E7-B4B5-E140DB21082A} = {B3D9DF87-38B1-4397-A4F5-9F6C45063E1B}
{CA4AC978-0A6F-4B86-B805-DFE2F6904DAF} = {2550698D-C602-4592-8DEF-C15AF6C6E46F}
{719956BA-2B70-404C-A8CB-F780623F4178} = {CA4AC978-0A6F-4B86-B805-DFE2F6904DAF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44DC5620-2F91-4082-84BB-AA4895AD0037}
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ This repo provides easily management hook operations of for dotnet application.
***

### Getting Started
Install `IronHook.PostgreSql` from [Nuget Package](https://www.nuget.org/packages/IronHook.PostgreSql)
Install `IronHook.EntityFramework.PostgreSql` from [Nuget Package](https://www.nuget.org/packages/IronHook.PostgreSql)

Initalize `Startup` configuration.

```csharp
services.AddIronHook(options =>
{
options.UseNpgsql(Configuration.GetConnectionString("{YOUR_CONNECTION_STRING}"));
options.UseNpgsql(
Configuration.GetConnectionString("{YOUR_CONNECTION_STRING}"),
opts => opts.UseIronHookNpgsqlMigrations()
);
});
```

Expand All @@ -58,7 +61,7 @@ after
```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseIronHook();
app.MigrateIronHook();
// ...
}
```
Expand Down
1 change: 0 additions & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<Version>1.0.0</Version>
<LangVersion>latest</LangVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand Down
5 changes: 2 additions & 3 deletions samples/IronHook.Web/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using IronHook.Core.Abstractions;
using IronHook.Core.Primitives;
using IronHook.PostgreSql.Context;
using IronHook.Web.Context;
using IronHook.Web.Dtos;
using IronHook.Web.Entities;
Expand All @@ -23,7 +22,7 @@ namespace IronHook.Web.Controllers
public class CustomersController : ControllerBase
{
private readonly SampleDbContext sampleDbContext;
private readonly IHookService<IronHookPostgreSqlDbContext> hookService;
private readonly IHookService hookService;

/// <summary>
/// Ctor
Expand All @@ -34,7 +33,7 @@ public class CustomersController : ControllerBase
/// <param name="hookService">
/// Hook Service
/// </param>
public CustomersController(SampleDbContext sampleDbContext, IHookService<IronHookPostgreSqlDbContext> hookService)
public CustomersController(SampleDbContext sampleDbContext, IHookService hookService)
{
this.sampleDbContext = sampleDbContext;
this.hookService = hookService;
Expand Down
5 changes: 2 additions & 3 deletions samples/IronHook.Web/Controllers/HookController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using IronHook.Core.Abstractions;
using IronHook.Core.Entities;
using IronHook.PostgreSql.Context;
using IronHook.Web.Dtos;
using Microsoft.AspNetCore.Mvc;
using System;
Expand All @@ -18,15 +17,15 @@ namespace IronHook.Web.Controllers
[Route("hooks")]
public class HookController : ControllerBase
{
private readonly IHookService<IronHookPostgreSqlDbContext> hookService;
private readonly IHookService hookService;

/// <summary>
/// Ctor
/// </summary>
/// <param name="hookService">
/// Hook Operation Service
/// </param>
public HookController(IHookService<IronHookPostgreSqlDbContext> hookService)
public HookController(IHookService hookService)
{
this.hookService = hookService;
}
Expand Down
6 changes: 3 additions & 3 deletions samples/IronHook.Web/IronHook.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\IronHook.PostgreSql\IronHook.PostgreSql.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.MarkdownDocumenting" Version="2.3.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
Expand All @@ -25,6 +22,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\IronHook.EntityFrameworkCore.PostgreSql\IronHook.EntityFrameworkCore.PostgreSql.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Docs\PostgreSql\Step3.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
9 changes: 3 additions & 6 deletions samples/IronHook.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
using IronHook.EntityFrameworkCore.PostgreSql.Extensions;
using IronHook.PostgreSql.Extensions;
using IronHook.Web.Context;
using MarkdownDocumenting.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace IronHook.Web
{
Expand All @@ -33,7 +30,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddIronHook(options =>
{
options.UseNpgsql(Configuration.GetConnectionString("Default"));
options.UseNpgsql(Configuration.GetConnectionString("Default"), opts => opts.UseIronHookNpgsqlMigrations());
});

services.AddDbContext<SampleDbContext>(options =>
Expand Down Expand Up @@ -70,7 +67,7 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseIronHook();
app.MigrateIronHook();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand Down
2 changes: 1 addition & 1 deletion samples/IronHook.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Default": "{YOUR_CONNECTION_STRING}"
"Default": "{YOUR_CONNECTIONSTRING_HERE}"
},
"DocumentationOptions": {
"HighlightJsStyle": "//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.8/styles/zenburn.min.css",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;

namespace IronHook.Web.Controllers;

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
17 changes: 17 additions & 0 deletions samples/dotnet6/IronHook.Web/IronHook.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\IronHook.EntityFrameworkCore.PostgreSql\IronHook.EntityFrameworkCore.PostgreSql.csproj" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions samples/dotnet6/IronHook.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
31 changes: 31 additions & 0 deletions samples/dotnet6/IronHook.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:12418",
"sslPort": 44317
}
},
"profiles": {
"IronHook.Web": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7052;http://localhost:5052",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
12 changes: 12 additions & 0 deletions samples/dotnet6/IronHook.Web/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IronHook.Web;

public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
}
9 changes: 9 additions & 0 deletions samples/dotnet6/IronHook.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion src/IronHook.Core/Abstractions/IHookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace IronHook.Core.Abstractions
/// <summary>
/// This interface includes business endpoints for Hook
/// </summary>
public interface IHookService<TDbContext> where TDbContext : IIronHookContext
public interface IHookService
{
/// <summary>
/// Add Hook
Expand Down
6 changes: 3 additions & 3 deletions src/IronHook.Core/Concrete/DefaultHookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace IronHook.Core.Concrete
{
public class DefaultHookService<TDbContext> : IHookService<TDbContext> where TDbContext : IIronHookContext
public class DefaultHookService : IHookService
{
private readonly TDbContext dbContext;
private readonly IIronHookContext dbContext;
private readonly IHookOperator hookOperator;

public DefaultHookService(TDbContext dbContext, IHookOperator hookOperator)
public DefaultHookService(IIronHookContext dbContext, IHookOperator hookOperator)
{
this.dbContext = dbContext;
this.hookOperator = hookOperator;
Expand Down
Loading