Register decorators
It would be cool if we were somehow able to add decorators via[RegisterSingleton/Scoped/Transient(decorateWith = typeof(SomeDecorator)]. Or using additional [Decorate(…)] resp.[DecorateWith<…>] attributes.
I totally agree. One issue that has held me back from implementing this is how to order the decorators. Any ideas, perhaps an order property?
My first idea thinking of only the [DecorateWith<…>] attribute a few weeks ago was just the order in which the attributes were applied/detected above the class to decorate - and I still think it would be the best default. But that would simply be not enough control as soon as one wants to globally apply decorators and thus an ordering property would be needed. But IMHO the user should be free to use strings, ints or even enums…
Any updates on this one? I really like the library (I just started using it), but the ability to use the decorator pattern would allow me to remove scrutor and use the source generator approach. Scrutor is using the order in which you call Decorate, and a similar approach can be added here, look at: https://github.com/YairHalberstadt/stronginject?tab=readme-ov-file#decorators Maybe the decorator attribute should be applied to the class that we want to decorate?
[RegisterSingleton(ServiceType = typeof(IService))]
[RegisterDecorator(DecoratorType = typeof(MyServiceDecorator) ,ServiceType = typeof(IService))]
[RegisterDecorator(DecoratorType = typeof(MyServiceDecorator2) ,ServiceType = typeof(IService))]
This way, we could have multiple decorators in a specific order.