Skip to content

Commit

Permalink
refactor: switch to primary constructors in most places
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyakunin committed Aug 23, 2023
1 parent c11201d commit b9fbbaa
Show file tree
Hide file tree
Showing 211 changed files with 358 additions and 757 deletions.
4 changes: 1 addition & 3 deletions samples/HelloCart/v2/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DbCartItem
public decimal Quantity { get; set; }
}

public class AppDbContext : DbContextBase
public class AppDbContext(DbContextOptions options) : DbContextBase(options)
{
public DbSet<DbProduct> Products { get; protected set; } = null!;
public DbSet<DbCart> Carts { get; protected set; } = null!;
Expand All @@ -33,8 +33,6 @@ public class AppDbContext : DbContextBase
// Stl.Fusion.EntityFramework tables
public DbSet<DbOperation> Operations { get; protected set; } = null!;

public AppDbContext(DbContextOptions options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var cart = modelBuilder.Entity<DbCart>();
Expand Down
4 changes: 1 addition & 3 deletions samples/TodoApp/Services/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

namespace Templates.TodoApp.Services;

public class AppDbContext : DbContextBase
public class AppDbContext(DbContextOptions options) : DbContextBase(options)
{
// Stl.Fusion.EntityFramework tables
public DbSet<DbUser<string>> Users { get; protected set; } = null!;
public DbSet<DbUserIdentity<string>> UserIdentities { get; protected set; } = null!;
public DbSet<DbSessionInfo<string>> Sessions { get; protected set; } = null!;
public DbSet<DbKeyValue> KeyValues { get; protected set; } = null!;
public DbSet<DbOperation> Operations { get; protected set; } = null!;

public AppDbContext(DbContextOptions options) : base(options) { }
}
2 changes: 1 addition & 1 deletion src/Stl.CommandR/CommanderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Stl.CommandR;

public readonly struct CommanderBuilder
{
private class AddedTag { }
private class AddedTag;
private static readonly ServiceDescriptor AddedTagDescriptor = new(typeof(AddedTag), new AddedTag());

public IServiceCollection Services { get; }
Expand Down
3 changes: 1 addition & 2 deletions src/Stl.CommandR/Commands/IBackendCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ namespace Stl.CommandR.Commands;
/// MVC action filter preventing such commands from being executed
/// via any of your public endpoints.
/// </remarks>
public interface IBackendCommand : ICommand
{ }
public interface IBackendCommand : ICommand;
2 changes: 1 addition & 1 deletion src/Stl.CommandR/Compatibility/CompilerServices.Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
6 changes: 2 additions & 4 deletions src/Stl.CommandR/Configuration/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ public override string ToString()
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
}

public abstract record CommandHandler<TCommand> : CommandHandler
public abstract record CommandHandler<TCommand>(Symbol Id, bool IsFilter = false, double Priority = 0)
: CommandHandler(Id, typeof(TCommand), IsFilter, Priority)
where TCommand : class, ICommand
{
protected CommandHandler(Symbol id, bool isFilter = false, double priority = 0)
: base(id, typeof(TCommand), isFilter, priority) { }

public override string ToString() => base.ToString();

// This record relies on reference-based equality
Expand Down
6 changes: 2 additions & 4 deletions src/Stl.CommandR/ICommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace Stl.CommandR;

public interface ICommand
{ }
public interface ICommand;

public interface ICommand<TResult> : ICommand
{ }
public interface ICommand<TResult> : ICommand;
3 changes: 1 addition & 2 deletions src/Stl.CommandR/ICommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Stl.CommandR;

public interface ICommandHandler
{ }
public interface ICommandHandler;

public interface ICommandHandler<in TCommand> : ICommandHandler
where TCommand : class, ICommand
Expand Down
3 changes: 1 addition & 2 deletions src/Stl.CommandR/ICommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
namespace Stl.CommandR;

// A tagging interface for proxy types
public interface ICommandService : IRpcService
{ }
public interface ICommandService : IRpcService;
13 changes: 4 additions & 9 deletions src/Stl.Fusion.Blazor.Authentication/AuthState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@

namespace Stl.Fusion.Blazor.Authentication;

public class AuthState : AuthenticationState
public class AuthState(User? user, bool isSignOutForced = false)
: AuthenticationState(user.OrGuest().ToClaimsPrincipal())
{
public new User? User { get; }
public bool IsSignOutForced { get; }
public new User? User { get; } = user;
public bool IsSignOutForced { get; } = isSignOutForced;

public AuthState() : this(null) { }
public AuthState(User? user, bool isSignOutForced = false)
: base(user.OrGuest().ToClaimsPrincipal())
{
User = user;
IsSignOutForced = isSignOutForced;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
namespace Stl.Fusion.Blazor.Authentication;

public class ChangeAuthStateUICommand : ICommand<AuthState>
{ }
public class ChangeAuthStateUICommand : ICommand<AuthState>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
2 changes: 1 addition & 1 deletion src/Stl.Fusion.Blazor/FusionBlazorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Stl.Fusion.Blazor;

public readonly struct FusionBlazorBuilder
{
private class AddedTag { }
private class AddedTag;
private static readonly ServiceDescriptor AddedTagDescriptor = new(typeof(AddedTag), new AddedTag());

public FusionBuilder Fusion { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace Stl.Fusion.EntityFramework.Npgsql.Operations;

public class NpgsqlDbOperationLogChangeNotifier<TDbContext>
: DbOperationCompletionNotifierBase<TDbContext, NpgsqlDbOperationLogChangeTrackingOptions<TDbContext>>
public class NpgsqlDbOperationLogChangeNotifier<TDbContext>(
NpgsqlDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services
) : DbOperationCompletionNotifierBase<TDbContext, NpgsqlDbOperationLogChangeTrackingOptions<TDbContext>>(options, services)
where TDbContext : DbContext
{
public NpgsqlDbOperationLogChangeNotifier(
NpgsqlDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services)
: base(options, services) { }

// Protected methods

protected override async Task Notify(Tenant tenant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@

namespace Stl.Fusion.EntityFramework.Npgsql.Operations;

public class NpgsqlDbOperationLogChangeTracker<TDbContext>
: DbOperationCompletionTrackerBase<TDbContext, NpgsqlDbOperationLogChangeTrackingOptions<TDbContext>>
public class NpgsqlDbOperationLogChangeTracker<TDbContext>(
NpgsqlDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services
) : DbOperationCompletionTrackerBase<TDbContext, NpgsqlDbOperationLogChangeTrackingOptions<TDbContext>>(options, services)
where TDbContext : DbContext
{
public NpgsqlDbOperationLogChangeTracker(
NpgsqlDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services)
: base(options, services) { }

protected override DbOperationCompletionTrackerBase.TenantWatcher CreateTenantWatcher(Symbol tenantId)
=> new TenantWatcher(this, tenantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace Stl.Fusion.EntityFramework.Conversion;

public class MomentToDateTimeValueConverter : ValueConverter<Moment, DateTime>
{
public MomentToDateTimeValueConverter(ConverterMappingHints? mappingHints = null)
: base(
v => v.ToDateTime(),
v => v.DefaultKind(DateTimeKind.Utc).ToMoment(),
mappingHints)
{ }
}
public class MomentToDateTimeValueConverter(ConverterMappingHints? mappingHints = null)
: ValueConverter<Moment, DateTime>(
v => v.ToDateTime(),
v => v.DefaultKind(DateTimeKind.Utc).ToMoment(),
mappingHints);
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace Stl.Fusion.EntityFramework.Conversion;

public class NewtonsoftJsonSerializedToStringValueConverter<T>
: ValueConverter<NewtonsoftJsonSerialized<T>, string>
{
public NewtonsoftJsonSerializedToStringValueConverter(ConverterMappingHints? mappingHints = null)
: base(
v => v.Data,
v => NewtonsoftJsonSerialized.New<T>(v),
mappingHints)
{ }
}
public class NewtonsoftJsonSerializedToStringValueConverter<T>(ConverterMappingHints? mappingHints = null)
: ValueConverter<NewtonsoftJsonSerialized<T>, string>(
v => v.Data,
v => NewtonsoftJsonSerialized.New<T>(v),
mappingHints);
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace Stl.Fusion.EntityFramework.Conversion;

public class SymbolToStringValueConverter : ValueConverter<Symbol, string>
{
public SymbolToStringValueConverter(ConverterMappingHints? mappingHints = null)
: base(
v => v.Value,
v => new Symbol(v),
mappingHints)
{ }
}
public class SymbolToStringValueConverter(ConverterMappingHints? mappingHints = null)
: ValueConverter<Symbol, string>(
v => v.Value,
v => new Symbol(v),
mappingHints);
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace Stl.Fusion.EntityFramework.Conversion;

public class UlidToStringValueConverter : ValueConverter<Ulid, string>
public class UlidToStringValueConverter(ConverterMappingHints mappingHints = null!)
: ValueConverter<Ulid, string>(x => x.ToString(), x => Ulid.Parse(x), DefaultHints.With(mappingHints))
{
private static readonly ConverterMappingHints DefaultHints = new(26, unicode: false);

public UlidToStringValueConverter(ConverterMappingHints mappingHints = null!)
: base(x => x.ToString(), x => Ulid.Parse(x), DefaultHints.With(mappingHints))
{ }
}
6 changes: 2 additions & 4 deletions src/Stl.Fusion.EntityFramework/DbEntityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ public interface IDbEntityConverter<TDbEntity, TModel>
TModel? ToModel(TDbEntity? source);
}

public abstract class DbEntityConverter<TDbContext, TDbEntity, TModel> : DbServiceBase<TDbContext>,
IDbEntityConverter<TDbEntity, TModel>
public abstract class DbEntityConverter<TDbContext, TDbEntity, TModel>(IServiceProvider services)
: DbServiceBase<TDbContext>(services), IDbEntityConverter<TDbEntity, TModel>
where TDbContext : DbContext
where TDbEntity : class
where TModel : notnull
{
protected DbEntityConverter(IServiceProvider services) : base(services) { }

public abstract TDbEntity NewEntity();
public abstract TModel NewModel();

Expand Down
4 changes: 2 additions & 2 deletions src/Stl.Fusion.EntityFramework/DbHints.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Stl.Fusion.EntityFramework;

public abstract record DbHint(Symbol Value) { }
public abstract record DbHint(Symbol Value);

public record DbLockingHint(Symbol Value) : DbHint(Value)
{
Expand All @@ -16,4 +16,4 @@ public record DbWaitHint(Symbol Value) : DbHint(Value)
public static DbLockingHint SkipLocked { get; } = new(nameof(SkipLocked));
}

public record DbCustomHint(Symbol Value) : DbHint(Value) { }
public record DbCustomHint(Symbol Value) : DbHint(Value);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Stl.Fusion.EntityFramework.Internal;

public sealed class DbHintFormatterExtensionInfo : DbContextOptionsExtensionInfo
public sealed class DbHintFormatterExtensionInfo(IDbContextOptionsExtension extension)
: DbContextOptionsExtensionInfo(extension)
{
public new DbHintFormatterOptionsExtension Extension => (DbHintFormatterOptionsExtension) base.Extension;
public override bool IsDatabaseProvider => false;
Expand All @@ -14,10 +15,6 @@ public override string LogFragment {
}
}

public DbHintFormatterExtensionInfo(IDbContextOptionsExtension extension)
: base(extension)
{ }

#if NET6_0_OR_GREATER
public override int GetServiceProviderHashCode() => 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

namespace Stl.Fusion.EntityFramework.Operations;

public class FileBasedDbOperationLogChangeNotifier<TDbContext>
: DbOperationCompletionNotifierBase<TDbContext, FileBasedDbOperationLogChangeTrackingOptions<TDbContext>>
public class FileBasedDbOperationLogChangeNotifier<TDbContext>(
FileBasedDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services
) : DbOperationCompletionNotifierBase<TDbContext, FileBasedDbOperationLogChangeTrackingOptions<TDbContext>>(options, services)
where TDbContext : DbContext
{
public FileBasedDbOperationLogChangeNotifier(
FileBasedDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services)
: base(options, services) { }

protected override Task Notify(Tenant tenant)
{
var filePath = Options.FilePathFactory(tenant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace Stl.Fusion.EntityFramework.Operations;

public class FileBasedDbOperationLogChangeTracker<TDbContext>
: DbOperationCompletionTrackerBase<TDbContext, FileBasedDbOperationLogChangeTrackingOptions<TDbContext>>
public class FileBasedDbOperationLogChangeTracker<TDbContext>(
FileBasedDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services
) : DbOperationCompletionTrackerBase<TDbContext, FileBasedDbOperationLogChangeTrackingOptions<TDbContext>>(options, services)
where TDbContext : DbContext
{
public FileBasedDbOperationLogChangeTracker(
FileBasedDbOperationLogChangeTrackingOptions<TDbContext> options,
IServiceProvider services)
: base(options, services) { }

protected override DbOperationCompletionTrackerBase.TenantWatcher CreateTenantWatcher(Symbol tenantId)
=> new TenantWatcher(this, tenantId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ namespace System.Runtime.CompilerServices;
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
internal static class IsExternalInit;
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Stl.Fusion.Authentication.Services;

public class DbAuthIsolationLevelSelector<TDbContext> : DbIsolationLevelSelector<TDbContext>
public class DbAuthIsolationLevelSelector<TDbContext>() : DbIsolationLevelSelector<TDbContext>(null)
where TDbContext : DbContext
{
public DbAuthIsolationLevelSelector() : base(null) { }

public override IsolationLevel GetCommandIsolationLevel(CommandContext commandContext)
{
var command = commandContext.UntypedCommand;
Expand Down
Loading

0 comments on commit b9fbbaa

Please sign in to comment.