ExternalAnnotations icon indicating copy to clipboard operation
ExternalAnnotations copied to clipboard

Add MediatR

Open hadrienbecle opened this issue 1 year ago • 3 comments

Adds annotations for MediatR, a widely used mediator library.

It marks as implicitly used all implementations of MediatR services implicitly added to the DI with services.AddMediatR().

hadrienbecle avatar Apr 19 '23 08:04 hadrienbecle

May I suggest two more annotations? These get rid of the 'class' is never instantiated green suggestion.

    <member name="T:MediatR.IRequest">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>
    <member name="T:MediatR.IRequest`1">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>

victor-borges avatar Jun 09 '23 14:06 victor-borges

May I suggest two more annotations? These get rid of the 'class' is never instantiated green suggestion.

    <member name="T:MediatR.IRequest">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>
    <member name="T:MediatR.IRequest`1">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>

Hey, @victor-borges .

You have two errors:

  1. MeansImplicitUseAttribute cannot be applied to interfaces, but UsedImplicitlyAttribute will suffice
  2. IRequest is not declared in "MediatR" assembly, it is from "MediatR.Contracts" (yes, it is located in the "Mediatr" namespace, but is packed into separate assembly, see here)

so, let me correct you: probably we need another file (MediatR.Contracts.xml) with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<assembly name="MediatR.Contracts">
    <member name="T:MediatR.INotification">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
    <member name="T:MediatR.IRequest">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
    <member name="T:MediatR.IRequest`1">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
</assembly>

Please note I've added INotification as well.

@hadrienbecle It would be nice of you if you'll add "Mediatr.Contracts.xml" to your PR.

andriibratanin avatar Feb 11 '24 10:02 andriibratanin

May I suggest two more annotations? These get rid of the 'class' is never instantiated green suggestion.

    <member name="T:MediatR.IRequest">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>
    <member name="T:MediatR.IRequest`1">
        <attribute ctor="M:JetBrains.Annotations.MeansImplicitUseAttribute.#ctor" />
    </member>

Hey, @victor-borges .

You have two errors:

1. `MeansImplicitUseAttribute` cannot be applied to interfaces, but `UsedImplicitlyAttribute` will suffice

2. `IRequest` is not declared in "MediatR" assembly, it is from "MediatR.Contracts" (yes, it is located in the "Mediatr" _namespace_, but is packed into separate _assembly_, see [here](https://github.com/jbogard/MediatR/blob/master/src/MediatR.Contracts/IRequest.cs))

so, let me correct you: probably we need another file (MediatR.Contracts.xml) with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<assembly name="MediatR.Contracts">
    <member name="T:MediatR.INotification">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
    <member name="T:MediatR.IRequest">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
    <member name="T:MediatR.IRequest`1">
        <attribute ctor="M:JetBrains.Annotations.UsedImplicitlyAttribute.#ctor(JetBrains.Annotations.ImplicitUseTargetFlags)">
            <argument>4</argument>
        </attribute>
    </member>
</assembly>

Please note I've added INotification as well.

@hadrienbecle It would be nice of you if you'll add "Mediatr.Contracts.xml" to your PR.

Thanks for the heads-up! I didn't pay attention to the changes made to the IRequest assembly location, I took those annotations out of a project made before 2022, back then it still lived in the main Mediatr assembly.

victor-borges avatar Feb 13 '24 14:02 victor-borges