How do you use Grace with the .Net 6.0 "minimal api"
See original GitHub issueLove you lib, been using it for years.
I’m trying to figure out how to use Grace with the new “minimal api” templates for .Net 6.0. I’d call it “Startup-less”, since there is no magic Startup.cs class.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0
Specifically, in my old Startup.cs I had the following magic:
public virtual void ConfigureContainer(IInjectionScope scope)
{
scope.Configure(c =>
{
c.Export<UserResolver>().As<IUserResolver>().Lifestyle.Singleton();
c.Export<HttpHeaderResolver>().As<IHttpHeaderResolver>();
c.Export<Profile>().As<IProfile>();
}
}
In the above article, to access the built-in DI container, you do the following:
var app = builder.Build();
app.MapControllers();
using (var scope = app.Services.CreateScope())
{
var sampleService = scope.ServiceProvider.GetRequiredService<SampleService>();
sampleService.DoSomething();
}
How do you accomplish the same with Grace?
Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Tutorial: Create a minimal API with ASP.NET Core
Start Visual Studio 2022 and select Create a new project. · In the Create a new project dialog: Enter Empty in the Search...
Read more >David Grace's Post
One of my favourite features of .NET 6 is Minimal APIs. Minimal APIs allows you to put API endpoints in the Program.cs file...
Read more >NET 6.0 - Minimal API Tutorial and Example
A step by step tutorial on how to build a minimal .NET 6.0 API from scratch with a couple of example endpoints/routes, with...
Read more >Minimal APIs in .NET 6
In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples....
Read more >Minimal APIs in .NET 6 — A Complete Guide(Beginners ...
NET6, you can use extension methods that come with minimal APIs. app.MapGet(“/books”, async (BooksDB db) =>await db.Books.ToListAsync()) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, I was doing .UseGrace, but needed to know how to get direct access to the container in the main() as opposed to the Startup.cs. It seems like your new syntax compiles. I need to throw a little more code together to make sure it’s all working.
Does this look correct?
Yes, that did. Thanks for all your help.