question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the difference between AddLamar() and UseLamar()?

See original GitHub issue

I expected both of these tests to pass but the first one doesn’t. What am I missing?

[Fact]
public void ServiceCollection_AddLamar()
{
    var services = new ServiceCollection();
    services.AddLamar();
    var provider = services.BuildServiceProvider();

    using (var scope = provider.CreateScope())
    {
        Assert.IsType<Container>(scope);
    }
}

[Fact]
public void HostBuilder_UseLamar()
{
    var hostBuilder = new HostBuilder();
    hostBuilder.UseLamar();
    var host = hostBuilder.Build();

    using (var scope = host.Services.CreateScope())
    {
        Assert.IsType<Container>(scope);
    }
}

I can live with using HostBuilder but just don’t understand why the difference.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremydmillercommented, Jul 20, 2020

@RyanThomas73 You’re treading into “I take pull requests” territory here. I’m happy to take a PR if you want this, but nobody else is asking for this feature.

0reactions
RyanThomas73commented, Jul 20, 2020

@jeremydmiller The point of being able to use the the BuildServiceProvider() is that the requirement of passing it into a lamar container constructor is misleading from an isolation / decoupling standpoint. Lamar’s service registry implements IServiceCollection but this is misleading, as the implementation can only be correctly used when combined with the lamar container.

IServiceCollection serviceCollection = SharedLibraryOrHelperToSetupDefaultServiceCollection();

// Working with an IServiceCollection here I would expect it to work as an IServiceCollection without 
// requiring the consumer of SharedLibraryOrHelperToSetupDefaultServiceCollection() to know or care
// that this service collection is implemented using Lamar and requires them to consume is a special way for it to work.
var serviceProvider = serviceCollection.BuildServiceProvider();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Integration with ASP.Net Core - Lamar
Net Core, you also need to call the UseLamar() method as shown below: ... you'll use the same ConfigureContainer() albeit with a different...
Read more >
Lamar - Getting Started
To get started, just add Lamar to your project through Nuget. Most of the time you ... Net Core, you also need to...
Read more >
Lamar 1.0: Faster, modernized successor to StructureMap
Net Core style registrations natively; There is no semantic difference between Add() and Use() like there was in StructureMap.
Read more >
StructureMap
There is no semantic difference between Add () and Use() like there was in StructureMap. Last one in wins. Just like ASP.Net Core...
Read more >
How to use Lamar in ASP.Net Core
Take advantage of Lamar, the speedy successor to StructureMap, to inject dependencies in ASP.Net Core.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found