JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
563 stars 118 forks source link

Adding Lamar to ASP.NET Core 6 minimal hosting breaks when adding AddControllersWithViews #320

Closed revbones-dev closed 2 years ago

revbones-dev commented 2 years ago

In a site that works (ASP.NET Core 6) if I add

builder.Host.UseLamar((context, registry) => {
registry.AddControllers(); registry.AddControllersWithViews(); registry.AddRazorPages(); });

The routing no longer works. If I remove those lines and put them outside the UseLamar call, then the site's routing works fine.

jeremydmiller commented 2 years ago

So, put them outside of the UseLamar() call just like you did. I think there's some hidden magic w/ the AddControllers() call that looks through previously registered services to determine the application assembly and finds things from there. If you'd be up for that, I'd happily take a pull request updating the documentation to call that out.

Otherwise, I don't think there's anything actionable here.

JohnBall007 commented 2 years ago

Thanks @revbones-duplicate. I had the same problem but deferred diagnosing it. This was the fix. The example in the .NET core minimal hosting proposes one variation which is a normal starting point: https://jasperfx.github.io/lamar/guide/#lamar-with-asp-net-core-minimal-hosting

jeremydmiller commented 2 years ago

I'm closing this as there's nothing actionable besides maybe a change in documentation.