Skip to content

Dependency properties don't work with keys #119

@RandomEngy

Description

@RandomEngy

Dependency properties don't seem to work with keys.

public class Test : ITest
{
    [Import(Key = "abc")]
    public IDep MyDep1 { protected get; set; }

    [Import(Key = "def")]
    public IDep MyDep2 { protected get; set; }

    public void DoAThing()
    {
        Console.WriteLine("Did a thing");
    }
}

...

var container = new DependencyInjectionContainer();
container.Configure(c => c.ImportMember<object>(MembersThat.HaveAttribute<ImportAttribute>()));
container.Configure(c => c.Export<Dep1>().AsKeyed<IDep>("abc"));
container.Configure(c => c.Export<Dep2>().AsKeyed<IDep>("def"));
container.Configure(c => c.Export<Test>().As<ITest>());

IDep myDep = container.Locate<IDep>(withKey: "abc"); // Works
ITest test = container.Locate<ITest>(); // Fails, can't import the dependency property

Exception is:

Grace.DependencyInjection.Exceptions.LocateException: 'Could not locate Type TestConsoleApp.IDep

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions