Skip to content

Commit

Permalink
Work around JsonSerializer limitation.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNieuwoudt committed Jan 2, 2020
1 parent 2e21848 commit 8ab79a2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
14 changes: 9 additions & 5 deletions StarCommander.Domain/Players/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace StarCommander.Domain.Players
{
public class Player : IAggregate
{
protected Player()
{
}

Player(Reference<Player> id, string callSign, string firstName, string lastName, byte[] passwordHash,
byte[] passwordSalt)
{
Expand All @@ -15,11 +19,11 @@ public class Player : IAggregate
PasswordSalt = passwordSalt;
}

public string CallSign { get; }
public string FirstName { get; }
public string LastName { get; }
public byte[] PasswordHash { get; }
public byte[] PasswordSalt { get; }
public string CallSign { get; protected set; }
public string FirstName { get; protected set; }
public string LastName { get; protected set; }
public byte[] PasswordHash { get; protected set; }
public byte[] PasswordSalt { get; protected set; }

public Guid Id { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace StarCommander.Infrastructure.Persistence.Aggregate.Players
{
public class Player : JsonEntity<Domain.Players.Player>
public class Player : JsonEntity<Domain.Players.Player, PlayerJson>
{
public string CallSign { get; set; } = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace StarCommander.Infrastructure.Persistence.Aggregate.Players
{
// ReSharper disable once ClassNeverInstantiated.Global
public class PlayerJson : Domain.Players.Player
{
public new string CallSign
{
get => base.CallSign;
set => base.CallSign = value;
}

public new string FirstName
{
get => base.FirstName;
set => base.FirstName = value;
}

public new string LastName
{
get => base.LastName;
set => base.LastName = value;
}

public new byte[] PasswordHash
{
get => base.PasswordHash;
set => base.PasswordHash = value;
}

public new byte[] PasswordSalt
{
get => base.PasswordSalt;
set => base.PasswordSalt = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace StarCommander.Infrastructure.Persistence.Aggregate.Players
{
public class PlayerRepository : JsonRepositoryBase<Domain.Players.Player, Player, PlayerDataContext>,
public class PlayerRepository : JsonRepositoryBase<Domain.Players.Player, PlayerJson, Player, PlayerDataContext>,
IPlayerRepository
{
public PlayerRepository(IAmbientDbContextConfigurator ambientDbContextConfigurator) : base(
Expand Down
4 changes: 2 additions & 2 deletions StarCommander.Infrastructure.Persistence/JsonEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace StarCommander.Infrastructure.Persistence
{
public abstract class JsonEntity<T> where T : class, IAggregate
public abstract class JsonEntity<T, TU> where T : class, IAggregate where TU : class, T
{
public Guid Id { get; set; }

Expand All @@ -23,7 +23,7 @@ protected virtual void ProjectValues(T aggregate)

public T ToDomain()
{
return (T)JsonSerializer.Deserialize(Json, typeof(T));
return JsonSerializer.Deserialize<TU>(Json);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

namespace StarCommander.Infrastructure.Persistence
{
public abstract class JsonRepositoryBase<T, TU, TV> : RepositoryBase<TV>, IRepository<T>
public abstract class JsonRepositoryBase<T, T1, TU, TV> : RepositoryBase<TV>, IRepository<T>
where T : class, IAggregate
where TU : JsonEntity<T>
where T1 : class, T
where TU : JsonEntity<T, T1>
where TV : class, IDbContext
{
protected JsonRepositoryBase(IAmbientDbContextConfigurator ambientDbContextConfigurator) : base(
Expand Down

0 comments on commit 8ab79a2

Please sign in to comment.