-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Hi! I am migrating from autofac to grace ioc and ran into an issue. Suppose such a structure (simplified):
class AService
{
private readonly Func<ADependency> _func;
public AService(Func<ADependency> func) =>
_func = func;
public ADependency GetDependency() =>
_func();
}
class ADependency
{
public ADependency(AService a)
{
}
}
Autofac registration works fine:
var autofacContainerBuilder = new ContainerBuilder();
autofacContainerBuilder.RegisterType<ADependency>();
autofacContainerBuilder.RegisterType<AService>();
var autofacContainer = autofacContainerBuilder.Build();
var s1 = autofacContainer.Resolve<AService>();
Unfortunately, when i port it to grace, i got a RecursiveLocateException:
var graceContainer = new DependencyInjectionContainer();
graceContainer.Configure(c =>
{
c.Export<ADependency>();
c.Export<AService>(); // throws!
// c.ExportFactory<IExportLocatorScope, AService>(scope => new AService(scope.Locate<Func<ADependency>>())); // work
});
var s2 = graceContainer.Locate<AService>();
I found a workaround (commented), but it looks rather ugly. Is there a more elegant way to solve this problem?
Metadata
Metadata
Assignees
Labels
No labels