Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to make dependency requirements a bit more visible #5817

Open
smoogipoo opened this issue May 30, 2023 · 0 comments
Open

A way to make dependency requirements a bit more visible #5817

smoogipoo opened this issue May 30, 2023 · 0 comments

Comments

@smoogipoo
Copy link
Contributor

smoogipoo commented May 30, 2023

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:

image

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:

image

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:
image

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.:

image

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.

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

No branches or pull requests

1 participant