-
Notifications
You must be signed in to change notification settings - Fork 29
Minimal API example #37
-
Although there is WebAPI example, it is still not clear how to apply this pattern to modern minimal APIs. Ideally, I'd have one root and bind all the services in that composition but not sure what the proper way is.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 2 replies
-
@Serg046 I've added an example that uses a single composition root in a minimal web application. Hopefully it will clarify the use cases. Feel free to ask questions if something is not clear, I will answer and add it to the documentation.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you Nikolay, I get the idea. The only thing is that ILogger<Program> logger is not resolved for me. It works if I move it lower so that it is resolved from the original container, like this
internal partial class Program( IWeatherForecastService weatherForecast) { private void Run(WebApplication app) { app.MapGet("/", async (ILogger<Program> logger) => { logger.LogInformation("Start of request execution"); return await weatherForecast.CreateWeatherForecastAsync().ToListAsync(); }); app.Run(); } }
Do you have the same? Do you have an idea how to make your exact sample working?
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you Nikolay, I get the idea. The only thing is that
ILogger<Program> loggeris not resolved for me. It works if I move it lower so that it is resolved from the original container, like this
It looks weird.
Do you have the same? Do you have an idea how to make your exact sample working?
Works for me in both scenarios.
Have you experimented with this example? Or your own? If you have your own, please make sure your composition is defined like this.
Are you able to share it?
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks again, your sample helped. I had to put builder.Host.UseServiceProviderFactory(composition) before builder.Build() which is quite obvious eventually but I didn't notice
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1