Skip to content

[Question/Suggestion]Why use Interfaces rather than Attributes? #31

Description

@oxayotl

Hi,

Coming from the Spring world, I was eager for something similar to how it deals with dependency injection. EasyScrutor is great and pretty close. However, I was wondering why it was relying on interfaces rather than the natural equivalent of Java's annotation, i.e. C#'s attribute.

Attributes seemed to me like a better fit because :

  • Semantically, I feel they represent some "extra" information on the class while Interfaces are more a "contract" the class has to respect
  • Practically, unlike Interfaces, they allow for arguments. So for instance, instead of being limited to ITransientLifetime and ISelfTransientLifetime, I can specify exactly which interface to inject as [InjectedTransient(As=typeof(IMyFavoriteInterface))]. Or I can even make it a list of type to inject as!

So being a pretty fresh user of C#, I was wondering if there were good reasons I had not realized yet that made interfaces a better fit? Is it much worse performance-wise, for instance? I did a small PoC on my current project and it seemed to work fine :) .
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions