switch to Newtonsoft.Json and config ti avoid cycle errors

This commit is contained in:
Ruidy Nemausat 2020-02-10 23:22:48 +01:00
parent ec9e31171e
commit 2f03b8f402
5 changed files with 14 additions and 4 deletions

3
.gitignore vendored
View file

@ -4,4 +4,5 @@ obj/
.vscode/ .vscode/
Migrations/ Migrations/
app.db app.db
client/node_modules client/node_modules
Scripts/

View file

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using TicketManager.Data; using TicketManager.Data;
using TicketManager.Models; using TicketManager.Models;
namespace TicketManager.Controllers namespace TicketManager.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]

View file

@ -18,8 +18,8 @@ namespace TicketManager.Models
public User Creator { get; set; } public User Creator { get; set; }
public Guid CreatorId { get; set; } public Guid CreatorId { get; set; }
// public Project Project { get; set; } public Project Project { get; set; }
// public int ProjectId { get; set; } public int ProjectId { get; set; }
private List<Note> _notes; private List<Note> _notes;
public List<Note> Notes public List<Note> Notes
{ {

View file

@ -17,6 +17,8 @@ using System.Reflection;
using System.IO; using System.IO;
using TicketManager.Data; using TicketManager.Data;
using TicketManager.Models; using TicketManager.Models;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Newtonsoft.Json;
namespace TicketManager namespace TicketManager
{ {
@ -34,7 +36,12 @@ namespace TicketManager
{ {
services.AddDbContext<AppDbContext>(options => services.AddDbContext<AppDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("Sqlite"))); options.UseSqlite(Configuration.GetConnectionString("Sqlite")));
services.AddControllers(); services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // avoid cycle ref errors
});
services.AddSpaStaticFiles(configuration => services.AddSpaStaticFiles(configuration =>
{ {
configuration.RootPath = "client/build"; configuration.RootPath = "client/build";

View file

@ -16,6 +16,7 @@
<ItemGroup> <ItemGroup>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.1.0" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.0" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">