You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# still lacks the ability to merge XMLDocs (dotnet/roslyn#60730), so we can't simply specify the required dependencies in our generated partial classes. It seems to be random as to which definition it uses.
This post serves as a place to track and discuss, and includes my investigations into alternatives.
1. Factory methods
A .Factory() method on drawable objects with a single method containing the dependencies:
Unfortunately, this seems to behave badly with Go to Declaration or Usages. There's a slim chance this is happening because one of the types is unresolved:
3. Constructor cloning + dependency list
Constructors are weird because optional params must be placed at the end of them.
The order in (2) above is { origRequired, depsRequired, origOptional, depsOptional }, but this may not always be intuitive when there are both optional dependencies and optional arguments, which isn't illustrated by the example.
A dependency list is a single object that coalesces all of these parameters, and itself can be made optional and placed at the very end of the constructor. E.g.:
Some drawables require so many dependencies that it can be difficult to track what environment the object needs. One such example is https://github.com/ppy/osu/blob/master/osu.Game/Overlays/Chat/DrawableChatUsername.cs
C# still lacks the ability to merge XMLDocs (dotnet/roslyn#60730), so we can't simply specify the required dependencies in our generated partial classes. It seems to be random as to which definition it uses.
This post serves as a place to track and discuss, and includes my investigations into alternatives.
1. Factory methods
A
.Factory()
method on drawable objects with a single method containing the dependencies:Try it out: https://github.com/smoogipoo/osu-framework/tree/sgen-di-create-method
2. Constructor cloning
Every constructor of the drawable object is cloned, and parameters are added for the dependencies:
Try it out: https://github.com/smoogipoo/osu-framework/tree/sgen-di-ctor-params
Unfortunately, this seems to behave badly with
Go to Declaration or Usages
. There's a slim chance this is happening because one of the types is unresolved:3. Constructor cloning + dependency list
Constructors are weird because optional params must be placed at the end of them.
The order in (2) above is
{ origRequired, depsRequired, origOptional, depsOptional }
, but this may not always be intuitive when there are both optional dependencies and optional arguments, which isn't illustrated by the example.A dependency list is a single object that coalesces all of these parameters, and itself can be made optional and placed at the very end of the constructor. E.g.:
Try it out: https://github.com/smoogipoo/osu-framework/tree/sgen-di-ctor-dependencylist
This also suffers from intellisense woes as in (2).
Note: The above examples may/will not compile. They're concepts.
The text was updated successfully, but these errors were encountered: