Skip to content

Refactor default parameters on interface, virtual methods #104

@JeremyCaney

Description

@JeremyCaney

In “Framework Design Patterns”, under 5.1 “General Member Design Guidelines”, the following recommendation should be followed:

  • DO NOT use default parameters, for any parameter type other than CancellationToken, on interface methods or virtual methods on classes.

This is inconsistent with how OnTopic is written. The recommended resolution is to instead implement the following:

Default parameters can be provided for interface methods via extension methods.

This relies on the method resolution logic of the C# compiler.

At minimum, this should be implemented on classes intended for dependency injection. For classes not intended for dependency injection, this may not be appropriate. See considerations below regarding using scope.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions