Search code examples
pluginsresharperrider

ReSharper SDK: possible to create directories and multiple files in Rider?


I'm using ASP.NET Core. A lot.

My project structure is as follows (example):

\Logic
  public ILogicStuff
  public IAdditionalLogicStuff
\Calculation
  internal IAddition
  internal ISubtraction
\Implementation
  \Logic
    internal LogicStuff : ILogicStuff
    internal AdditionalLogicStuff : IAdditionalLogicStuff
  \Calculation
    internal Addition : IAddition
    internal Subtraction : ISubtraction

I use my own "auto config" system which uses an attribute ([ImplementedBy(typeof(LogicStuff))]) to setup IoC (kilometer long lists of "AddSingleton" here and "AddTransient" there are inacceptable). This is solved, I simply use reflection on service startup and iterate through the whole app domain. Works like a charm.

What I would like to implement:

  1. Right click in the solution
  2. "Add new IoC component"
  3. My plugin then creates:
  • The interface (public in many cases, often also internal, but I think adding a checkbox here should be possible)
  • The [ImplementedBy] attribute
  • The proper subdirectory under \Implementation if it doesn't exist
  • The implementing class under \Implementation...

Is this doable with the ReSharper SDK so I can use this in Rider? I'm good in C# but have no clue when it comes to Java, so I'd prefer to use the ReSharper SDK.


Solution

  • I believe you can do this even without creating a custom plugin, but just by creating a (kind of advanced) file template. Rider supports creating several files from single template, putting them into specified folders and so on.

    The only limitation currently is UI for creating such template in Rider is not ready yet, so you can explore two possible options:

    1. Create such template in ReSharper multifile templates editor and import it into Rider. You can use free trial of ReSharper for this task.
    2. Manually craft the template without UI (not an easy thing, but as R#/Rider developer I would volunteer to help you with that). Please ping me if you would prefer this option

    Here is the documentation about this multifile templates: https://www.jetbrains.com/help/resharper/Templates__Creating_and_Editing_Templates__Multifile.html