MC
Metalama CommunityXaniff
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!
Petr Onderka•225d ago
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):
Xaniff•225d ago
Perfect - thank you
Want results from more Discord servers?
More PostsIntroduceDependency with record typesThe IntroduceDependencyAttribute used within the SimpleLogAttribute to inject an ILogger _logger isnGiving Aspects Metadata ?I've only just started messing with MetaLama and going thru the documentation and videos but I was wUnable to get aspect testing to workI've got a very simple class set up to apply a logging aspect to so I can get the hang down of testiHow to debug a "Cannot preview the transformed code: unknown error"?I've got an aspect that's building without error and a target project that's applying the aspect thaWarn on ineligibility instead of throwingI've got two conditions in my BuildEligibility for a method override aspect: If the target type is aReferencing value assigned to variable in statement builder within another statementGiven a statement that does something like:
```cs
var expr = new ExpressionBuilder();
expr.AppendVer