mfractor / mfractor-feedback

Found a bug or have a feature request for MFractor? Submit it here!
3 stars 0 forks source link

New Code Action: add service/dependency to class #279

Open ravero opened 3 years ago

ravero commented 3 years ago

When working on a project with DI, constructor injection is the most common way of adding a dependency (which will be resolved later by the DI framework).

I've thought that it could be a code action. A suggested workflow:

  1. The code action can be available anywhere inside a code class
  2. When invoking Add service or dependency to class a modal should be shown with a text field to search for a class or interface (with autocomplete as you type) and another to name the field.
  3. After selecting the type and setting the name, the code action would add:

Example:

public class Test
{
    readonly IService service;
    public Test(IService service) { this.service = service }

    // rest of the class implementation
}

Other considerations:

matthewrdev commented 3 years ago

@ravero I can see this being particularly useful for us while developing our app.

A few additional ideas:

ravero commented 3 years ago

@matthewrdev I agree with all your points.

I would still keep a text field on the dialog for customising the field name. Sometimes I want to simplify interfaces with compound names (like IServicesCollection, a builtin type on the Microsoft DI engine for ASP.NET Core that I frequently simplify to services).

The feature name is short and descriptive, I would go with it.