-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Minimal hosting" for ASP.NET Core applications #30354
Comments
For MVC why not using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
var app = WebApplication.CreateMvc(args);
await app.RunAsync();
public class HomeController
{
[HttpGet("/")]
public string HelloWorld() => "Hello World";
} where Looking through "beginner eyes":
|
I don't think it scales well. You need to undo CreateMvc or create more concepts if you want to do anything (like adding other features, or setting configuration options, or configuring pretty much anything). The key to this is not just making it simple to start but simple to grow up. We don't want to fork the framework concepts of ideas or make something that doesn't work with the existing ecosystem. That's why its super important to design something right in the middle that achieves the code brevity and reduces the concept count at the same time. Now we could consider including |
The current proposal for MVC adds builder, services and controllers.
Good point. So maybe make |
One of the goals is to reduce "unlearning". That is, the amount of code you need to undo once you need to do something additive. Also The MVC name doesn't mean much, o don't think it needs to be in the method. We'll experiment with what on by default would mean |
We'll have to figure out what to do with tools like EF migrations and WebApplicationFactory that depend on the current Program.CreateHostBuilder pattern. |
I'm not sure those are in scope (that's why testing is out of scope in the description above), or better put, we have to make a tradeoff somewhere and I'm ok if that's what needs to be traded off. |
Would we change the templates to use this new pattern? It would be problematic if EF migrations didn't work in the templates. |
Also, even for non-template scenarios, we should at least update the migration tool to recognize the new scenario enough to give a better error message. |
Undecided, I would like to but there are obviously problems beyond EF migrations (and other tools like it).
I think it does this today, if not, it should since that method can be easily removed. |
Thanks for contacting us. |
API Review:
|
What does this mean? |
That type doesn't have any ASP.NET dependencies and should live in the Extensions.Configuration packages. |
What does that have to do with Peek() |
Oh that was just an off hand comment I made, wasn't suggesting a name at the time, but just guessing what this mega type would be doing, its basically letting you 'Peek' at config values while still building the config. That seems like it could be generally useful so I can see why it was was mentioned in the same line as possible extensions enhancements. |
Made some API tweaks based on discussion today with @DamianEdwards |
@maryamariyan @ericstj @eerhardt We should discussion this new merged IConfigurationBuilder/IConfiguration type and where it belongs. |
We could investigate testability via something injected via a startup hook potentially. |
Actually could we potentially have tools like |
@davidfowl imagining this as a combination of |
The issue is communicating the instance of the service provider to the startup hook. We could use a diagnostic source or something like that. |
Just an FYI - startup hooks and diagnostic sources are not linker-friendly. Not sure how important it is in this scenario, but I just wanted to call it out. |
I can write one but I want to have a little design meeting with the team first. It's kinda crazy 😃 |
Aren't these overloads ambiguous because of the params? Why do you need the second one? And why does
|
We meant to remove the params overload in favor of the single argument one. I updated the comment to reflect that. |
Interesting choice, that precludes doing http and https together with this API. What's the fallback, UseAddresses? |
Old API? var builder = WebApplication.Create();
builder.WebHost.UseUrls(...);
var app = builder.Build();
My guess is that we want to wait for feedback to see how common it is to specify the URL? |
Btw, would we consider adding WebApplicationBuilder
{
+ public ICollection<string> Urls { get; }
} |
I was thinking about changing the type of public sealed class WebApplication : IHost, IApplicationBuilder, IEndpointRouteBuilder, IAsyncDisposable
{
- public IEnumerable<string> Addresses { get; }
+ public ICollection<string> Addresses { get; }
} Should I make that change for preview4? |
The quickest way to test that would be to remove the parameter from Run/Async and see if setting the url(s) is a common problem. |
You need to be able to set a URL. |
Sure, but is Run the right place for that? |
That was inspired by Listen(..) on nodejs' server API. |
I think we should definitely collect feedback on passing the URL directly to RunAsync. I'm going to make the |
hmm just made me wonder, if I can both attach middleware and routing with WebApplication, isn't there a conflict between two Map methods taking a string and request delegates? One maps a middleware based on path, one maps a routing endpoint? |
I also have additional question, what will be the role of generic host and web host then? used for non aspnetcore or very advanced cases, or intended to be deprecated, or what? I mean is it considered an old api or an advanced api? |
This is a good point but we don't have that conflict today. I'd imagine if you added methods that conflicted, the compiler would tell you it's ambiguous.
WebHostBuilder/WebHost is on a path to deprecation, but the IWebHostBuilder will stay around forever since all of the APIs hang off it. The generic host is also here to stay and will be the target for non web APIs. We haven't figured out how to message when to use one over the other as yet. The new host is built on top of the generic host internally so we don't have plans to replace that. I think it'll come down to the preference of calling
|
IMO it starts to be a bit messy :) but I admit the proposed api is pretty nice. I often have problems with when to use what, at least in case of webhost vs generic host it was more clear because it was obvious the latter replaces the former effectively. |
if there is no conflict when it goes to Map method, so how do you do Map? or is it something that is not useful? I mean the non routing Map one. |
Pff my bad. It seems there is no conflict, so my only concern is that there are two... well more than two, like... 5? methods named Map accessible from the new WebApplication, and some of them add a routing entry and others add a middleware in that exact place of pipeline. So possible confusion when someone looks up all extension methods :) but at least it's not going to yell at me for ambiguous methods. |
What would be the solution for multi-tenant solutions? Some of these don't have preconfigured URLs, they are configured at runtime by being read from a data-store or something. |
I'm not sure what that has to do with configuring the hosting URLs. |
My bad, hosting URLs are for Kestrel and WebListener, nothing to do with multi-tenancy. |
Summary
We want to introduce a new "direct hosting" model for ASP.NET Core applications. This is a more focused, low ceremony way of creating a web application.
Motivation and goals
Introducing a lower ceremony replacement for the WebHost to remove some of the ceremony in hosting ASP.NET Core applications. We've received lots of feedback over the years about how much ceremony it is to get a simple API up and running and we have a chance to improve that with the deprecation of the WebHost.
In scope
Out of scope
Risks / unknowns
Program.CreateHostBuilder()
which no longer existsStrawman proposal
The idea is to reduce the number of concepts while keeping compatibility with the ecosystem we have today. Some core ideas in this new model is to:
IApplicationBuilder
, theIEndpointRouteBuilder
and theIHost
into a single object. This makes it easy to register middleware and routes without needed an additional level of lambda nesting (see the first point).Examples
Hello World
Hello MVC
Integrated with 3rd party ASP.NET Core based frameworks (Carter)
More complex, taking advantage of the existing ecosystem of extension methods
cc @LadyNaggaga @halter73 @shirhatti
The text was updated successfully, but these errors were encountered: