Using Attributes to Call Methods

后端 未结 3 1748
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 12:38

I have various individual methods which all need to perform the same functions before continuing on with their own implementation. Now I could implement these functions in each

3条回答
  •  温柔的废话
    2021-02-07 13:05

    I don't think you can do this with attributes only, because they are not executed by the runtime if you're not actively doing something with them. A lightweight approach would be Ninject with Interceptions extension, it is a framework, but a very thin one, and one you might already be using for DI anyway.

    Another option, but a bit more involved, could be based on MEF, and then you can use attributes and do something during with them during activation.

提交回复
热议问题