-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DependencyMetadata<T> support for decorators #879
Comments
I'll note that the injection of public class DecoratorWithDependencyMetadataTests
{
[Fact]
public void SuccessfullyAppliesDecoratorWithDependencyMetadataToType()
{
var container = new Container();
container.Register<IDoTheThing, Thing>();
container.RegisterDecorator<IDoTheThing, Decorator1>();
container.RegisterDecorator<IDoTheThing, Decorator2>();
container.Verify(); // no exception thrown
container.GetInstance<IDoTheThing>().DoTheThing();
}
private interface IDoTheThing
{
void DoTheThing();
}
private class Thing : IDoTheThing
{
public void DoTheThing() { }
}
private class Decorator1 : IDoTheThing
{
private readonly IDoTheThing _thing;
private readonly DependencyMetadata<IDoTheThing> _dependencyMetadata;
public Decorator1(IDoTheThing thing, DependencyMetadata<IDoTheThing> dependencyMetadata)
{
_thing = thing;
_dependencyMetadata = dependencyMetadata;
}
public void DoTheThing() => _thing.DoTheThing();
}
private class Decorator2 : IDoTheThing
{
private readonly IDoTheThing _thing;
private readonly DependencyMetadata<IDoTheThing> _dependencyMetadata;
public Decorator2(IDoTheThing thing, DependencyMetadata<IDoTheThing> dependencyMetadata)
{
_thing = thing;
_dependencyMetadata = dependencyMetadata;
}
public void DoTheThing() => _thing.DoTheThing();
}
} |
@RyanMarcotte, that's peculiar. This behavior might be more accidental than intentional, because there are currently no unit tests to support that scenario. You might want to be careful with that until it is officially supported (and thoroughly tested). |
For sure. I will use |
Instead of adding support for |
@RyanMarcotte, good point. I will take this into consideration. |
I'd be happy to contribute a pull request once the desired behavior is finalized. Let me know! |
Simple Injector supports injecting metadata into decorators for a long time through the use of
DecoratorContext
. More recently (v5) metadata support has been added more broadly through the use ofDependencyMetadata<T>
. This, however, means that there are now two mechanisms to inject metadata. The decorator subsystem, unfortunately, doesn't support gettingDependencyMetadata<T>
injected which can be confusing, as reported in #878.The text was updated successfully, but these errors were encountered: