Manage creation and disposal of ITcpConnection
in AprsIsConnection
#124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, as unit tests require the ability to inject an
ITcpConnection
,AprsIsConnection
has a single constructor which requires specifying anITcpConnection
.However, most clients will not need or want to specify their own
ITcpConnection
, so this is overly cumbersome. Instead, this PR changes the incomingITcpConnection
to be optional.To handle ambiguity around if the
ITcpConnection
should be disposed, we follow the pattern laid out by Microsoft's own HttpClient, which allows injection of anHttpMessageHandler
and specifying whether the HttpClient or the caller should dispose the handler.For most clients of
AprsIsConnection
, they should simply callnew AprsIsConnection()
and allow the object to create and dispose resources. For special cases (tests or advanced resource management), they can call the injection constructor with theirITcpConnection
and instructions on if it should be disposed.Changes
AprsIsConnection
constructor overload to allow not passing in anITcpConnection
AprsIsConnection(ITcpConnection)
constructor toAprsIsConnection(ITcpConnection, bool)
to allow specifying who should dispose theITcpConnection
AprsIsConnection
disposable to facilitate destruction of resources and handle disposes in code and testsIDisposable
implementation fromTcpConnection
to the interfaceITcpConnection
to facilitate dispose codeITcpConnection.Dispose()
is only called at the right timesValidation
AprsIsConnection.Dispose()
logic