Skip to content

AutoActivate() hides a registration's default "self" service #1450

@nblumhardt

Description

@nblumhardt

Describe the Bug

A registration like builder.Register<A>() defaults to exposing the typed service A on the component.

Adding AutoActivate() to the registration hides this default. Since the name AutoActivate() doesn't suggest that it has anything to do with exposed services, this seems like a bug or rough edge in the API.

Steps to Reproduce

public class StartableTests
{
    [Fact]
    public void AutoActivate_DoesNotHideDefaultSelfService()
    {
        var builder = new ContainerBuilder();
        builder.RegisterType<MyComponent2>().AutoActivate();
        using var container = builder.Build();
        Assert.True(container.IsRegistered<MyComponent2>());
    }

The test can be made to succeed by adding AsSelf() to the registration.

Expected Behavior

AutoActivate() would not alter the services exposed by the component in a user-visible manner.

Dependency Versions

develop branch.

Additional Info

Happy to try to fix this and send a PR, just opening this first to gauge whether it's a known issue or by design. Not in any way blocked on this :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions