Skip to content

Microsoft.Extensions.DependencyInjection.AutoActivation is not working. #7499

@hatulaile

Description

@hatulaile

Description

Microsoft.Extensions.DependencyInjection.AutoActivation is not working.

Reproduction Steps

using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddActivatedSingleton<MyService>();
Console.WriteLine("Build Before");
ServiceProvider provider = services.BuildServiceProvider();
Console.WriteLine("Build After");
provider.GetRequiredService<MyService>();
Console.WriteLine("End");

class MyService
{
    public MyService() => Console.WriteLine("MyService Created");
}

Expected behavior

The expected output should be, in order:
"Build Before"
"MyService Created"
"Build After"
"End"

Actual behavior

The actual output is:
"Build Before"
"Build After"
"MyService Created"
"End"

Regression?

No response

Known Workarounds

No response

Configuration

Microsoft.Extensions.DependencyInjection: 10.0.7
Microsoft.Extensions.DependencyInjection.AutoActivation: 10.5.0

.NET SDK:
 Version:           10.0.203
 Commit:            c23858a6d8
 Workload version:  10.0.200-manifests.f8ca1cb9
 MSBuild version:   18.3.3+c23858a6d

 OS Name:     Windows
 OS Version:  10.0.26200
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.203\

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-compliancebugThis issue describes a behavior which is not expected - a bug.untriaged

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions