Skip to content
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

DependencyAttribute is ignored when injecting by name #287

Open
ENikS opened this issue Nov 6, 2020 · 0 comments
Open

DependencyAttribute is ignored when injecting by name #287

ENikS opened this issue Nov 6, 2020 · 0 comments

Comments

@ENikS
Copy link
Contributor

ENikS commented Nov 6, 2020

Description

A clear and concise description of what is wrong.

To Reproduce

Please provide UnitTest in the form of:

        public class ObjectWithAttributes
        {
            [Dependency("name1")]
            public string Dependency;
        }

Container.RegisterInstance(Name);
Container.RegisterInstance(Name, Name);
Container.RegisterInstance(Name1, Name1);


[TestMethod]
public void ResolveOverAttributeAny()
{
    // Setup
    Container.RegisterType<ObjectWithAttributes>(
        Resolve.Field(nameof(ObjectWithAttributes.Dependency)));

    // Act
    var result = Container.Resolve<ObjectWithAttributes>();

    // Verify
    Assert.IsNotNull(result);
    Assert.IsNotNull(result.Dependency);
    Assert.AreEqual(result.Dependency, Name1);
    Assert.IsNull(result.Optional);
}


[TestMethod]
public void ResolveOverAttribute()
{
    // Setup
    Container.RegisterType<ObjectWithAttributes>(
        new InjectionField(nameof(ObjectWithAttributes.Dependency), (string)null));

    // Act
    var result = Container.Resolve<ObjectWithAttributes>();

    // Verify
    Assert.IsNotNull(result);
    Assert.IsNotNull(result.Dependency);
    Assert.AreEqual(result.Dependency, Name);
    Assert.IsNull(result.Optional);
}

Additional context

Add any other context about the problem here.

@ENikS ENikS changed the title Resolve Over Attribute DependencyAttribute is ignored when injecting by name Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant