Top-level statements and WindowsApplicationBuilder #3456
Replies: 5 comments 3 replies
-
As an additional thought, I'm a little dissatisfied with this infrastructure, that we have in desktop development in generous. And I'm talking about such basic things, like navigation. Each time I'm creating a new project - I have to manually write some NavigationService. (Thanks to TemplateStudio it's not so painful) Because all I want to do is to write: var builder = WindowsApplication.CreateBuilder(args);
builder.UseApp<App>();
builder.Services.AddNavigation(); // From some library
var app = builder.Build();
app.UseNavigation();
// Or
app.UseNavigation(new MyCustomNavigationProvider()); // From some 3d party library
await app.StartAsync(); |
Beta Was this translation helpful? Give feedback.
-
I hate that top-level-statement bullshit with a passion, a *.cs file had a well defined structure until this got introduced. Adds complexity where it is not needed, so i am against it. |
Beta Was this translation helpful? Give feedback.
-
I do not really like the fact of DI containers being the default of a UI app like this. A lot of times I do not need them, especially when I'm just prototyping something so the extra overhead it adds is useless. Furthermore this also limits the type of DI container you can use, which will be the MSFT one. Also how would you handle app activation now from like a notification? I don't think this is good idea. You can obviously hack your way around to get the app to launch using a standard Program.cs and a main/args constructor, so the option is there if you really need it. I just don't think it's a good idea to bake it in like this. Also are you really making that many apps, that making a new navigation service (or putting them in your own class lib), takes up that much of your time? In fact, I think each app is different and would require its own logic for navigation. Some apps should have caching, some should absolutely not etc. This will just promote more bad apps IMO, because people will often opt for the default. Which may or may not be good. We don't know. |
Beta Was this translation helpful? Give feedback.
-
Hi @christosk92. My point here is that configuration of the app, and its activation should be separate. What about DI containers: if you're writing a simple ToDo app with code-behind - you don't need DI and can skip this step. But in my practice - you would like to set up some DI and inject services into ViewModels for appropriate logging, servicing, communication with external resources and so on.
I don't think so. With concept of WindowsApplication, which implements IHost you will be able to use huge amount of libraries, like:
var app = WindowsApplication.CreateBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.UseSerilog((hostBuilderContext, loggerConfiguration) => ...)
.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) => ...)
.Build(); |
Beta Was this translation helpful? Give feedback.
-
One more argument why we need a WindowsApplicationBuilder is testing. Using the same approach, we would be able to write elegant tests for desktop. |
Beta Was this translation helpful? Give feedback.
-
Hi WindowsAppSDK team and community 👋
With .NET 6 we got some improvement in the code structuring: top-level statements, that allows us to have "empty"
Program.cs
file.So, the
Program.cs
file in ASP.NET Core apps now looks like this:In MAUI
MauiProgram.cs
now looks this way:As a software engineer, I would like to see something similar in WindowsAppSDK projects.
So my propositions are:
Program.cs
fileWindowsApplicationBuilder
And the code should look like this:
Ideally, the
WindowsApplicationBuilder
should implementIHost
interface to be able to useMicrosoft.Extensions.Hosting
for further configurations, like Logging, Configuration, Dependency Injection and so on.Because, from my point of view, modern desktop development process is underdone.
And with such approach it will be more convenient for new users what to do. Dotnet in WindowsAppSDK will look like in other modern dotnet-family projects.
CONS:
The only one minus that I'm thinking of now - is C++ project template.
It will remain the old template structure, which might be a little bit confusing for developers, who are moving from one language to the other.
Beta Was this translation helpful? Give feedback.
All reactions