How to inject factory-based dependencies from method aspect into type?
Let's use an example - in Microsoft.Extensions.Logging, I might register an ILoggerFactory so I can inject it into a type's constructor and then build a field from that. For example, typically this might look like this usually:
So I'd like to do something similar here. It's not quite what the dependency injection framework does because I'm injecting one thing into the constructor, but then making something else from it.
And ideally, it's something that I could do from a MethodAspect because I want to be able to apply the attribute to various methods.
Is this possible? As always, thank you!
2 Replies
It's possible and it's documented here: https://doc.metalama.net/conceptual/aspects/dependency-injection#implementing-an-adaptor-for-a-new-dependency-injection-framework.
Specifically, it would look like this (using 2023.4.3-preview):
Perfect - thank you