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

Child container fails to resolve registered depencency #270

Open
publee opened this issue Oct 17, 2020 · 3 comments
Open

Child container fails to resolve registered depencency #270

publee opened this issue Oct 17, 2020 · 3 comments

Comments

@publee
Copy link

publee commented Oct 17, 2020

I am trying to resolve concrete type with dependency registered in child container, but it throws exception.

[Test]
public void TestMethod2()
{
    var container = new DependencyInjectionContainer();
    var childScope = container.CreateChildScope(c => c.Export<Service2>().As<IService2>());

    var service = childScope.Locate<Service>();//LocateException : Could not locate Type TestGraceIoc.UnitTest2+IService2

    Assert.IsInstanceOf<Service>(service);
    Assert.IsInstanceOf<Service2>(service.P1);
}

public interface IService2 { }
public class Service2 : IService2 { }

public class Service 
{
    public Service(IService2 p1)
    {
        P1 = p1;
    }
    public IService2 P1 { get; }
}
@ipjohnson
Copy link
Owner

@publee I appologize I missed this issue.

Technically speaking by default Grace won't look in a child container for a dependency. You can configure it that way but honestly it makes things slower.

I assume since this is more than a month old you either solved the problem or moved to a different container.

@publee
Copy link
Author

publee commented Nov 23, 2020

Can you please provide example how to configure Grace to look in a child container for a dependency?
Thank you.

@mcdis
Copy link

mcdis commented Jan 21, 2021

Hi @publee !

var container = new DependencyInjectionContainer(_ =>
{
  _.Behaviors.ConstructorSelection = ConstructorSelectionMethod.Dynamic;
});

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

3 participants