Skip to content

Commit

Permalink
Small improvements in a way how DBContext is handled in the controlle…
Browse files Browse the repository at this point in the history
…rs from plugins
  • Loading branch information
peterliapin committed Jan 24, 2024
1 parent 08ac935 commit fc620d2
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/OnlineSales/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using OnlineSales.Configuration;
using OnlineSales.Data;
using OnlineSales.DTOs;
using OnlineSales.Entities;
Expand Down
2 changes: 1 addition & 1 deletion src/OnlineSales/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BaseController<T, TC, TU, TD> : ControllerBase
protected readonly DbSet<T> dbSet;
protected readonly PgDbContext dbContext;
protected readonly IMapper mapper;
private readonly QueryProviderFactory<T> queryProviderFactory;
protected readonly QueryProviderFactory<T> queryProviderFactory;

public BaseController(PgDbContext dbContext, IMapper mapper, EsDbContext esDbContext, QueryProviderFactory<T> queryProviderFactory)
{
Expand Down
2 changes: 1 addition & 1 deletion src/OnlineSales/Entities/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum CommentStatus
[Table("comment")]
[SupportsElastic]
[SupportsChangeLog]
[SurrogateIdentityAttribute(nameof(Key))]
[SurrogateIdentity(nameof(Key))]
public class Comment : BaseEntity
{
private string authorEmail = string.Empty;
Expand Down
1 change: 0 additions & 1 deletion src/OnlineSales/Entities/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using Nest;
using OnlineSales.DataAnnotations;
Expand Down
3 changes: 0 additions & 3 deletions src/OnlineSales/Infrastructure/ESOnlyQueryProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
// </copyright>

using System.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Nest;
using OnlineSales.Configuration;
using OnlineSales.Data;
using OnlineSales.DataAnnotations;
using OnlineSales.Entities;
using OnlineSales.Interfaces;

Expand Down
13 changes: 9 additions & 4 deletions src/OnlineSales/Infrastructure/QueryProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// </copyright>

using System.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Nest;
using OnlineSales.Configuration;
Expand All @@ -18,9 +17,10 @@ public class QueryProviderFactory<T>
where T : BaseEntityWithId, new()
{
protected readonly IOptions<ApiSettingsConfig> apiSettingsConfig;
protected readonly IHttpContextHelper httpContextHelper;
protected readonly PgDbContext dbContext;
protected readonly ElasticClient elasticClient;
protected readonly IHttpContextHelper httpContextHelper;
protected readonly ElasticClient elasticClient;

protected PgDbContext dbContext;

public QueryProviderFactory(PgDbContext dbContext, EsDbContext esDbContext, IOptions<ApiSettingsConfig> apiSettingsConfig, IHttpContextHelper? httpContextHelper)
{
Expand Down Expand Up @@ -51,5 +51,10 @@ public virtual IQueryProvider<T> BuildQueryProvider(int limit = -1)
return new DBQueryProvider<T>(dbSet!.AsQueryable<T>(), queryBuilder);
}
}

public void SetDBContext(PgDbContext dbContext)
{
this.dbContext = dbContext;
}
}
}
1 change: 0 additions & 1 deletion src/OnlineSales/Infrastructure/TaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Diagnostics.CodeAnalysis;
using Medallion.Threading.Postgres;
using Microsoft.EntityFrameworkCore;
using OnlineSales.Data;
Expand Down
2 changes: 1 addition & 1 deletion src/OnlineSales/Migrations/PgDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("ProductVersion", "7.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
Expand Down
2 changes: 1 addition & 1 deletion src/OnlineSales/OnlineSales.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

<!--This ItemGroup is required to support migration generation with the "dotnet ef migrations add" command-->
<ItemGroup Condition="'$(Configuration)'=='Migration'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 0 additions & 5 deletions src/OnlineSales/Services/ActivityLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Configuration;
using System.Diagnostics;
using Microsoft.Identity.Client;
using Nest;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using OnlineSales.Data;
using OnlineSales.DTOs;
using OnlineSales.Entities;

namespace OnlineSales.Services
Expand Down

0 comments on commit fc620d2

Please sign in to comment.