Lamar 3.1 – New Diagnostics and more

Lamar 3.1.0 was published today with a few fixes, new diagnostics, and a newly improved equivalent to StructureMap’s old “Forward” registration. The full details are here.

There’s one big bug fix on multi-threaded usage that was impacting folks using Lamar with MediatR (it’s worth a later blog post about debugging problems because this took several folks and at least two attempts from me to finally diagnose and solve).

“Inverse” Registration

For the not uncommon need to have one single object be the implementation for multiple role interfaces within the container, there’s the new “inverse” registration mechanism as shown below:

[Fact]
public void when_singleton_both_interfaces_give_same_instance()
{
    var container = new Container(services =>
    {
        services.Use<Implementation>()
            .Singleton()
            .For<IServiceA>()
            .For<IServiceB>();
    });

    var instanceA = container.GetInstance<IServiceA>();
    var instanceB = container.GetInstance<IServiceB>();

    instanceA.ShouldBeTheSameAs(instanceB);
}

What you see above is registering the concrete type Implementation as the shared, underlying service for both IServiceA and IServiceBregistrations.

HowDoIBuild

Lamar has been able to show you the “build plan” for registrations since the beginning, but now there’s a helper Container.HowDoIBuild() method that gives you easier access to this information that can be helpful for troubleshooting IoC configuration issues.

Lamar.Diagnostics

More on this one later, but there’s also a brand new package called Lamar.Diagnostics that, in conjunction with Oakton.AspNetCore, adds command line access to all the Lamar diagnostic capabilities directly to your ASP.Net Core application.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s