microsoft / microsoft/aspire

Service discovery with DNS SRV is broken when using AutoFac

Open
#4,431 0 comments 0 reactions 0 assignees View on GitHub
area-service-discovery
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

When using AutoFac as a DI container, the following error is encountered when using `.AddDnsSrvServiceEndpointProvider()`:

```
Autofac.Core.DependencyResolutionException: Cannot choose between multiple constructors with equal length 1 on type 'DnsClient.LookupClient'. Select the constructor explicitly, with the UsingConstructor() configuration method, when the component is registered.
at Autofac.Core.Activators.Reflection.MostParametersConstructorSelector.SelectConstructorBinding(BoundConstructor[] constructorBindings, IEnumerable`1 parameters)
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Activators.Reflection.ReflectionActivator.b__13_0(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
```

The workaround is to re-register the `LookupClient` as below:

`.AddSingleton(_ => new LookupClient())`

however this should work out-of-the box without resorting to this workaround.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.