Microsoft Unity- Issue With Resolve

前端 未结 2 1491
情书的邮戳
情书的邮戳 2021-01-25 14:21

I am looking to do this:

container.Resolve();

When it does this, its going to inject a IDependency into the underlying entity object. However, the dependency st

相关标签:
2条回答
  • 2021-01-25 14:32

    Why don't you use the static factory extension?

    var container = new UnityContainer();
    container.AddNewExtension()
             .Configure()
             .RegisterFactory(container =>
                              DependencyFactory.GetValue());
    
    0 讨论(0)
  • 2021-01-25 14:49

    What if you register an implementation of the DependencyFactory in the container (either through code or config) an resolve through its interface. Then you would get the DependencyFactory injected and simply request the necessary object from it.

    Unlesss I'm understanding the scenario incorrectly, your class has a dependency, which is determined at runtime through a factory. As this is exactly what Unity does, you could use the correct instance registrations (for example using IDs) to use Unity as your DependencyFactory.

    I hope this helps.

    Thanks, Damian

    0 讨论(0)
提交回复
热议问题