Azure / Azure/azure-functions-host

Improve DryIoc error message when factory delegate returns null

Open
#6,068 8 comments 5 reactions 0 assignees View on GitHub
area: dependency injection
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

It seems like this exception is missing details -- and it'd be great if we could even catch this and log something more directly applicable to the user:

```
DryIoc.ContainerException : Registered factory delegate returns service is not assignable to ambiently scoped container with {no name, Parent={no name}}.
```

You can repro this if you do something like this in your Startup.cs:

```
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddSingleton(s =>
{
return null;
});
}
```

You wouldn't explicitly do this -- but some factory delegates can potentially return null, and when they do you are left with a fairly confusing message.

Contributor guide

Open the contributing guide

Research direction

Start with the Startup.cs registration shown in the issue and reproduce the ContainerException when the factory delegate returns null. Trace where this exception message is produced and verify that the completed change gives users more actionable details for a null factory result.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.