ipjohnson / Grace

Grace is a feature rich dependency injection container library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for properties dynamic import strategy

mcdis opened this issue · comments

commented

Like:

 Container = new DependencyInjectionContainer(_ =>
      {
         _.Behaviors.ConstructorSelection = ConstructorSelectionMethod.Dynamic; // < -- Like that
      });

But for property.
Locate type with [Import] attribute in sub container doesn't work

interface IDep{}
interface IFoo{}

class Dep : IDep {}
class Foo : IFoo
{
 [Import]
 public IDep Dep {get;init;}
}

// ----------------------
Container.Configure(_b=>_b.ExportAs<Dep,IDep>());

Container
  .CreateChildScope(_b=>_b
     .ExportAs<Foo,IFoo>()
     .ImportMembers(MembersThat.HaveAttribute<ImportAttribute>())
     .Lifestyle.Singleton()
  ).Locate<Foo>();

Sorry for the late response I've been AFK this past week. I can take a look this evening.

@ipjohnson did you ever get around to this? I am seeing similar behaviour on latest. Thanks for the awesome work!