-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Description
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