Skip to content

Commit

Permalink
Fix compiler warnings related to nullability in Tokens module (#506)
Browse files Browse the repository at this point in the history
* refactor: add nullable property group

* refactor: make RootFolder nullable

* refactor: make Tokens null!

* refactor: make Id required

* refactor: make ConverterMappingsHints nullable

* refactor: make Provider and DbConnectionString null!

* refactor: make fields required

* refactor: expression is never null according to nullable reference types' annotations

* refactor: conditional access qualifier expression is never null according to nullable reference types' annotations

* refactor: remove check since BlobStorageOptions never null

* fix: revert last made changes

* refactor: suppress null

* refactor: make field Content required

* refactor: remove expression for checking null

* refactor: allow BlobStorageOptions to be nullable

* refactor: revert BlobStorageOptions to null!

* refactor: make IdentityAddress nullable

* ci: trigger pipelines

* refactor: allow BlobStorageOptions to be null and initializes a new instance

* refactor: revert changes

* refactor: make BlobStorageOptions nullable

* refactor: make ExpresAt required

* refactor: make CreatedAt required

* refactor: make CreatedAt & ExpiresAt required

* chore: minor changes

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Timo Notheisen <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent 2baebb6 commit e7e611c
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion ConsumerApi/TokensDbContextSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TokensDbContextSeeder : IDbSeeder<TokensDbContext>
public TokensDbContextSeeder(IServiceProvider serviceProvider)
{
_blobStorage = serviceProvider.GetService<IBlobStorage>();
_blobRootFolder = serviceProvider.GetService<IOptions<BlobOptions>>()!.Value.RootFolder;
_blobRootFolder = serviceProvider.GetService<IOptions<BlobOptions>>()?.Value.RootFolder;
}

public async Task SeedAsync(TokensDbContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class BlobOptions
{
public string RootFolder { get; set; }
public string? RootFolder { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Backbone.Modules.Tokens.Application.Tokens.Commands.CreateToken;
[ApplyQuotasForMetrics("NumberOfTokens")]
public class CreateTokenCommand : IRequest<CreateTokenResponse>, IMapTo<Token>
{
public byte[] Content { get; set; }
public DateTime ExpiresAt { get; set; }
public required byte[] Content { get; set; }
public required DateTime ExpiresAt { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Backbone.Modules.Tokens.Application.Tokens.Commands.CreateToken;

public class CreateTokenResponse : IMapTo<Token>
{
public TokenId Id { get; set; }
public DateTime CreatedAt { get; set; }
public required TokenId Id { get; set; }
public required DateTime CreatedAt { get; set; }
}
12 changes: 6 additions & 6 deletions Modules/Tokens/src/Tokens.Application/Tokens/DTOs/TokenDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Backbone.Modules.Tokens.Application.Tokens.DTOs;

public class TokenDTO : IMapTo<Token>
{
public TokenId Id { get; set; }
public required TokenId Id { get; set; }

public IdentityAddress CreatedBy { get; set; }
public DeviceId CreatedByDevice { get; set; }
public required IdentityAddress CreatedBy { get; set; }
public required DeviceId CreatedByDevice { get; set; }

public DateTime CreatedAt { get; set; }
public DateTime ExpiresAt { get; set; }
public required DateTime CreatedAt { get; set; }
public required DateTime ExpiresAt { get; set; }

public byte[] Content { get; set; }
public required byte[] Content { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Backbone.Modules.Tokens.Application.Tokens.Queries.GetToken;

public class GetTokenQuery : IRequest<TokenDTO>
{
public TokenId Id { get; set; }
public required TokenId Id { get; set; }
}
3 changes: 0 additions & 3 deletions Modules/Tokens/src/Tokens.Domain/Tokens.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\BuildingBlocks\src\DevelopmentKit.Identity\DevelopmentKit.Identity.csproj" />
<ProjectReference Include="..\..\..\..\BuildingBlocks\src\Tooling\Tooling.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Tokens.Infrastructure\Tokens.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tokens.Infrastructure\Tokens.Infrastructure.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Tokens.Infrastructure\Tokens.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tokens.Infrastructure\Tokens.Infrastructure.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class IServiceCollectionExtensions
public static void AddDatabase(this IServiceCollection services, Action<DbOptions> setupOptions)
{
var options = new DbOptions();
setupOptions?.Invoke(options);
setupOptions.Invoke(options);

services.AddDatabase(options);
}
Expand Down Expand Up @@ -53,8 +53,8 @@ public static void AddDatabase(this IServiceCollection services, DbOptions optio

public class DbOptions
{
public string Provider { get; set; }
public string DbConnectionString { get; set; }
public string Provider { get; set; } = null!;
public string DbConnectionString { get; set; } = null!;
public RetryOptions RetryOptions { get; set; } = new();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ namespace Backbone.Modules.Tokens.Infrastructure.Persistence.Database;

public class TokensDbContext : AbstractDbContextBase
{
public TokensDbContext() { }
public TokensDbContext()
{
}

public TokensDbContext(DbContextOptions<TokensDbContext> options) : base(options) { }
public TokensDbContext(DbContextOptions<TokensDbContext> options) : base(options)
{
}

public TokensDbContext(DbContextOptions<TokensDbContext> options, IServiceProvider serviceProvider) : base(options, serviceProvider) { }
public TokensDbContext(DbContextOptions<TokensDbContext> options, IServiceProvider serviceProvider) : base(options, serviceProvider)
{
}

public virtual DbSet<Token> Tokens { get; set; }
public virtual DbSet<Token> Tokens { get; set; } = null!;

//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
//{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class TokenIdEntityFrameworkValueConverter : ValueConverter<TokenId, stri
{
public TokenIdEntityFrameworkValueConverter() : this(null) { }

public TokenIdEntityFrameworkValueConverter(ConverterMappingHints mappingHints)
public TokenIdEntityFrameworkValueConverter(ConverterMappingHints? mappingHints)
: base(
id => id == null ? null : id.StringValue,
id => id.StringValue,
value => TokenId.Parse(value),
mappingHints
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class IServiceCollectionExtensions
public static void AddPersistence(this IServiceCollection services, Action<PersistenceOptions> setupOptions)
{
var options = new PersistenceOptions();
setupOptions?.Invoke(options);
setupOptions.Invoke(options);

services.AddPersistence(options);
}
Expand All @@ -26,13 +26,12 @@ public static void AddPersistence(this IServiceCollection services, PersistenceO
services.Configure<BlobOptions>(blobOptions => blobOptions.RootFolder = options.BlobStorageOptions.Container);
}


services.AddRepositories();
}
}

public class PersistenceOptions
{
public DbOptions DbOptions { get; set; } = new();
public BlobStorageOptions BlobStorageOptions { get; set; }
public BlobStorageOptions? BlobStorageOptions { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<DbPaginationResult<Token>> FindAllOfOwner(IdentityAddress owne
return await Find(owner, Array.Empty<TokenId>(), paginationFilter, cancellationToken);
}

private async Task<DbPaginationResult<Token>> Find(IdentityAddress owner, IEnumerable<TokenId> ids, PaginationFilter paginationFilter, CancellationToken cancellationToken)
private async Task<DbPaginationResult<Token>> Find(IdentityAddress? owner, IEnumerable<TokenId> ids, PaginationFilter paginationFilter, CancellationToken cancellationToken)
{
if (paginationFilter == null)
throw new Exception("A pagination filter has to be provided.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e7e611c

Please sign in to comment.