Skip to content

Registering an Existing Instance? #423

@MattHoneycutt

Description

@MattHoneycutt

According to the docs, it should be possible to register an existing object when the type isn't known at compile time. The docs show this:

[Fact]
public void should_be_able_to_resolve_from_the_generic_family_expression()
{
    var widget = new AWidget();
    var container = new Container(x => x.For(typeof(IWidget)).Use(widget).Named("mine"));

    container.GetInstance<IWidget>("mine").ShouldBeTheSameAs(widget);
}

However, it looks like there isn't an overload of Use that will accept an instance. The exact code from the docs fails.

I also found this old issue (2020) that shows this was implemented: #233

Is there a different, preferred way to register an existing object when the type isn't compile-time constant?

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