Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

This PR implements the enhancement requested in issue #35 by adding constructor overloads to the Disposable class that allow directly setting the AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts properties without requiring inheritance.

Changes Made

  • New Constructor Overloads: Added optional parameters allowMultipleDisposeCalls and allowMultipleDisposeAttempts to all existing constructors:

    • Disposable(Action action, bool allowMultipleDisposeCalls = false, bool allowMultipleDisposeAttempts = false)
    • Disposable(Disposal disposal, bool allowMultipleDisposeCalls = false, bool allowMultipleDisposeAttempts = false)
    • Disposable(bool allowMultipleDisposeCalls, bool allowMultipleDisposeAttempts = false)
  • Property Overrides: Override the virtual properties AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts to return constructor-provided values when set, falling back to base implementation when not.

  • Comprehensive Tests: Added 6 new unit tests covering all constructor scenarios:

    • Tests for new constructor functionality with both properties enabled
    • Tests for backward compatibility (existing constructors still work as before)
    • Demonstration test showing how the new constructors replace the inheritance workaround
  • Bug Fix: Updated DisposalOrderTest to use .NET 8 instead of .NET 7 target framework

Before (Required Inheritance Workaround)

public class DisposableWithMultipleCallsAllowed : Disposable
{
   public DisposableWithMultipleCallsAllowed(Disposal disposal) : base(disposal) { }
   protected override bool AllowMultipleDisposeCalls => true;
}

After (Direct Constructor Usage)

var disposable = new Disposable(disposal, allowMultipleDisposeCalls: true);

Test Results

All tests pass (11/11):

  • 6 new constructor tests
  • 5 existing tests (including the previously failing DisposalOrderTest)

Backward Compatibility

This change is fully backward compatible. All existing code will continue to work exactly as before, with the new parameters defaulting to false (maintaining current behavior).

🤖 Generated with Claude Code


Resolves #35

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #35
@konard konard self-assigned this Sep 14, 2025
…llowMultipleDisposeAttempts

- Add constructor parameters to allow setting AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts values directly instead of requiring inheritance
- Add comprehensive tests to verify new constructor functionality
- Fix DisposalOrderTest to use net8 target framework instead of net7
- Resolves issue #35: Add constructor that can override values of AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts properties

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add constructor that can override values of AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts properties Add constructor overloads to override AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 05:18
@konard
Copy link
Member Author

konard commented Oct 30, 2025

Hi! 👋

I'm investigating issue linksplatform/Data.Doublets#122, which depends on this PR being merged.

This PR looks excellent - all tests pass, it's fully backward compatible, and it provides exactly the functionality requested in issue #35.

Status check: Is there anything blocking this PR from being merged? Any changes needed, or is it just waiting for review?

The Data.Doublets repository is ready to remove its workaround inner class as soon as:

  1. This PR is merged ✅ (pending)
  2. A new version is released to NuGet 📦 (pending)

Looking forward to seeing this feature available! Thanks for your work on this. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add constructor that can override values of AllowMultipleDisposeCalls and AllowMultipleDisposeAttempts properties

2 participants