.NET 6 Startup Changes - Handling Program.cs Without Startup.cs

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 109

  • @Gramr98
    @Gramr98 2 роки тому +15

    Tim, I just wanted to mention that you are an absolute blessing to this community. You're making it so much easier for me and everyone else to get into the new technologies. I only used to do Console and Forms Application, but now I can do (and actually understand!) stuff that I never would have dreamed off. If UA-cam never recommended you to me, it would have been very likely that I would have left Software Development a while ago and went somewhere else. Please, never stop what you're doing!

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +3

      I appreciate the kind words.

  • @rodrigo_sparlock
    @rodrigo_sparlock 2 роки тому +31

    Hi, Tim! Thanks a lot for your videos. Even I'm not an English native speaker, I can understand everything. Your content is very valuable, clear, and well produced.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +5

      Awesome! Thanks for sharing.

  • @TysonGibby
    @TysonGibby 2 роки тому +1

    Hi Tim, will you also start posting your videos to Rumble? I would much rather watch them there.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I have no plans to put my content on Rumble at this time.

    • @TysonGibby
      @TysonGibby 2 роки тому

      @@IAmTimCorey Thanks Tim.

  • @recepsergenkoleoglu8078
    @recepsergenkoleoglu8078 Рік тому

    How can I change the system time of the project in Program.cs in .NET 6 without taking into account the system time of the server?

  • @georgevlassis8319
    @georgevlassis8319 2 роки тому +1

    I have this question. I have a Web API at which I want to add a library that makes payments. That library has to call another api, that is the payments api. So that library has to implement HttpClient. The right way to do it is through DI, but DI can only be done at the Startup of the main project which is the Web API but then it's like taking something that belongs to the library and putting it at the Web API. Is it wrong to do it like this, maybe the HttpClient should be at the main project and not the library. Note that other than that the main project does not need to implement HttpClient.

    • @mannetjie3704
      @mannetjie3704 2 роки тому +1

      i think it makes more sense to put something closest to where it will be used from. unless the httpclient will be will be implemented in a shared way across multiple projects or by other teams, ie. a library meant as a nuget package or such. am i misunderstanding? anyway, you can still have your container (DI) setup in the library if you want, as an IServiceCollection extension method. then you just call it from any "main" project startup.

  • @badass6300
    @badass6300 2 роки тому +2

    Yes, I really dislike this change, since I just started learning ASP NET Core and this change was annoying, both due to it being a decent change, but also I dislike the new program.cs files. I love my namespaces, classes and methods. Thanks for the video.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      Well, at least you know how to work with them now.

    • @CRBarchager
      @CRBarchager 2 роки тому

      If you still want the old setup you can always just start a net5.0 project and then change it to net60. Then the Program.cs/Services.cs files will be there but your project is .Net 6. I did this to day when I had to upgrade my .NET 3.1 project -> .Net6.0

    • @lcsantos85
      @lcsantos85 2 роки тому +4

      This.
      Get rid of Startup.cs, hmm but fine. Now getting rid of namespaces, classes, main() method? Aren't we overdoing it? It's kind of aesthetically unpleasant and I don't see the great benefit of having code thrown in a blank unstructured .cs file.

    • @badass6300
      @badass6300 2 роки тому

      @@lcsantos85 My thoughts exactly.

  • @chrisjohansson9971
    @chrisjohansson9971 2 роки тому +1

    If you already started a project in .net 5 that created startup and program and then upgraded to .net 6. It still keeps those files and runs them like .net5. I guess you would have to manually remove startup and change program.cs then in this case? Is there any benefit or point of doing this other then "this is the new way of doing it" when you upgrade.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      You don't need to change over, no. It is only necessary if you want to have the benefits of it.

  • @aimene_.
    @aimene_. 2 роки тому +1

    Even if you are not a native english, you can undrestand videos of Tim with x2 speed, Tim is a legend ! Thank you

  • @josephh8117
    @josephh8117 Рік тому

    OHHHH I was looking for hours for the answer to the Endpoint question ( 13:12 ).. No app.UseEndPoints() wrap necessary in 6.0... THANKS!!!

  • @codefoxtrot
    @codefoxtrot 2 роки тому +5

    Thanks Tim. I'm grateful when your topics begin with 'let's open Visual Studio and get started.' Being able to demo a topic as close to the default templates as possible means I can follow along from the same starting point. Often times, I find other videos that start right in the middle of something. Sure, the presenter knows their project and topic very well, but often times overlooks something foundational and it's just harder to follow along. So I, for one, always appreciate your format, no matter how large or small the topic.

  • @julionunes2092
    @julionunes2092 2 роки тому +4

    I really like Microsoft's products. However, in my opinion, there's a real challenging (mainly for begginners) to make a project with c# because of this changes. Many tutorials on youtube ended up being outdated. I think this is very annoying and confusing sometimes. Anyway, thank you Tim for all your videos, they are really great.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +3

      The good news is that they aren't really outdated. You just need to use the same version of .NET as they did to follow along. The code is still modern and relevant. Even code from .NET Framework projects still mostly works the same way in .NET 6. Progress has to happen, but they still maintain support for previous generations.

  • @KvarkLt
    @KvarkLt 2 роки тому

    Could you please show how to control asembly path in .net 6 as per now all dll goes in root and not working from dll folder - its seam related as they change of startup process I think (in version .net 5 that was controled by probing privatePath from config.json)

  • @sprtybi
    @sprtybi 6 місяців тому

    Thank you Tim. You explain very simply and clearly ❤

  • @CheeseBae
    @CheeseBae 2 роки тому

    Looks to me like they're trying to make it feel more Javascript-y.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      Languages tend to blend into one another as they modernize together. In this case, though, they are just trying to eliminate repetitive and unnecessary code.

  • @Sad-Lemon
    @Sad-Lemon 2 роки тому

    Hi Tim. Great vid, as always. Very informative!
    I don't like the way where it is going... what's next? Implicit projects? /:P

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +2

      This change just moved things into one file and made them clearer, though. I think that’s a good thing. I like the idea of eliminating things that aren’t needed. Why do we need to have a Main method declaration when we cannot call it? Why do we need to indent our entire code base just to declare a namespace for the entire file? Yes, we are used to these the way they were, but that doesn’t mean they were better that way.

  • @guriysamarin6204
    @guriysamarin6204 2 роки тому

    In dotnet 5 you could omit Main method. In 6.0 it got promoted to be the default way.

  • @waleedbensumaidea3947
    @waleedbensumaidea3947 2 роки тому

    I want to learn ASP.NET core.
    Which version do you recommend..
    Net 6
    Or other

    • @IAmTimCorey
      @IAmTimCorey  Рік тому +1

      To get started, learn the latest (.NET 6). However, don't stop there. Once you are comfortable with the latest, learn earlier versions as well (.NET Core 3.1 and .NET Framework). That is because businesses are typically behind in their versions. Knowing older versions will give you an advantage when it comes to getting a job. If you are starting a new application, though, start with the latest version of .NET.

    • @waleedbensumaidea3947
      @waleedbensumaidea3947 Рік тому

      @@IAmTimCorey thank you so much for the advice

  • @GarrattCampton
    @GarrattCampton 2 роки тому

    Hey Tim, following along your paid C# course and up to mongoDB for the most part up until now I've been just omiting "public/private" etc statements from methods which seem to still allow me to create methods within the program.cs class but the mongodb part is where it became all unstuck for me. So would it be easier if I just create a new class "Controls.cs" and call that straight away from this main program.cs and then put everything else into controls i would otherwise put into main() had I been using .Net 5.
    Also side note, my version of VS2022 community (new install) doesn't allow the option of changing down to .Net5 and lower. (unless I select .Net Framework) all core classes are Net6 and the dropdown shows no other options.

    • @GarrattCampton
      @GarrattCampton 2 роки тому

      nevermind, figured I'd use class controller in that one and for the rest I can select "Don't use top level statements" when starting a project.

  • @argelpamintuango1956
    @argelpamintuango1956 2 роки тому

    so if our application is using inheritance in multiple csproj files, we have to remove those because microsoft ruined the startup for us

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      No, that's not what it means. I'm not exactly sure how using inheritance will cause any issues, but the .NET 6 projects still work fine with Startup.cs. The templates just do not include it by default. You can add it back or you can create a template that has it or you can create a .NET 5 project and then upgrade it to .NET 6 (just change the version in the csproj file) and it will work just fine.

    • @argelpamintuango1956
      @argelpamintuango1956 2 роки тому

      @@IAmTimCorey what about if our application running in .net framework that uses owin library? would owin data annotation attached on the startup.cs class still work on .net 6?

  • @aviadmoses7925
    @aviadmoses7925 2 роки тому

    Hi Tim, Thanks a lot for your effort with making these lessons. they are very helpful.
    One small question that i noticed that is different in my environment:
    In WASM6 project--> Program.cs --> line 6 and 7, there are kind of labels "selector:".
    What R they and why in my environment, VS2022 Community Edition, i'm not able to see them?
    Is there any special configuration for that?

  • @trustingod0
    @trustingod0 2 роки тому

    Mr. Corey you are the Greatest Teacher of Programming I have ever listened to. I am going to enroll in your online courses. If you could please help me to understand this small piece of code it would help me tremendously. I dont understand what "options =>" means. Is this a lambda expression? Can I use another word instead of options? Thanks !!!!
    services.AddDbContext(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

  • @adamm9706
    @adamm9706 2 роки тому

    MVC 18:49

  • @vishal_shivhare
    @vishal_shivhare Рік тому

    TimCorey, you're the best

  • @cristiandragusin3814
    @cristiandragusin3814 2 роки тому +1

    You are amazing!

  • @codmn1824
    @codmn1824 2 роки тому

    If i had money, I would send you some, with all this information you are giving us for free. We really love you and pray for you Corey.

  • @wellingtonsantos355
    @wellingtonsantos355 2 роки тому

    You are amazing. Thanks for giving us so much knowledge. Greetings from Brazil!

  • @kalleguld
    @kalleguld 2 роки тому

    Startup.cs always seemed odd to me. It feels like there should be an interface, but there isn't. This new format is way better.

  • @samlegend6064
    @samlegend6064 2 роки тому

    Hello Tim! Thanks for this Productive Session. Can you please make a video for comparison between .NET and others stuff like Node etc. Because nowadays as we all know the market is going towards js back-end and front-end and also .Net jobs are reducing gradually. Most of the time we see the collaboration of Node + React jobs WHY?
    We love .NET and wanted it to spread like others. What is your thoughts about it Please make a video.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I think a lot of these sentiments are anecdotal rather than accurate. .NET/C# has been on the rise for years. The strength of .NET Core has made it an increasingly popular language. That doesn't mean you won't find local areas that do not reflect that reality.

  • @matervam4550
    @matervam4550 2 роки тому

    Ridiculous really. Typical Microsoft, they go 3 steps forward, and then one back. What is the purpose of killing off the Program and the Startup? Do we really get any benefit from this? So that it can be more like javascript and Node? Who really wants to create yet another js scripter?
    Minimal API approach - who writes a real life application that way? It is not even original - NancyFx had this approach years ago. We are not using .Net to make a fashion statement but to solve real life business challenges.
    On top of all that, people have to now figure out the dependency injection and everything else when wiring-up the projects, so this is simply a drawback. They should have focused on delivering the MAUI and not just postponing it like that, but I guess this was too important that it took precedence.
    At least I can still do .Net 5 -> Create Projects -> change to .Net 6.
    OK, not the first and surely not the last stupid decision MS had made.
    Thanks for the video.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      I don't agree here. There was a LOT of ceremony around creating an application in C#. We don't need all of it. Compressing everything into Program.cs simplified things since there is now one place for all startup configuration instead of two.
      Minimal APIs are REALLY helpful in certain circumstances (and you don't have to enable them, by the way). When building microservices, it doesn't make sense to have a massive project with lots of files to support a few endpoints.
      Dependency injection is something that almost every application should have set up. We used to have to do it manually. Now it is already done for us, which makes using it simple. Also, if we want to use a third-party DI system, we just make a few tweaks in Program.cs and we are set.
      I think the biggest issue here is that .NET is becoming more modern. While that's important to stay relevant, it does mean changes to how we do things. Change can be hard, but it is necessary, especially in software development.
      MAUI is being developed by a different team. The delay on MAUI had nothing to do with .NET 6 except that the changes needed to support MAUI came in .NET 6 (which is why MAUI didn't also come in .NET 6).

    • @matervam4550
      @matervam4550 2 роки тому

      ​@@IAmTimCorey Thank you for your reply. I do not agree with you, but maybe because it seems we are coming from very different places.
      Now chronologically:
      1. "There was a lot ceremony around creating application.." - not at all, you create the application from the template, and it is just there. You do not do any work. Now they are compressing it in one-liners, but the same work is done hidden from you within the framework. There is no benefit, just more complicated as we need to dig much deeper if we were to do any wiring-up even slightly from what the "minimal" approach offers us.
      2. "Minimal APIs are really usefull...." - not at all, this can be only useful for when writing simple blogs, as you just get rid of the things you do not need since the topic would be something else, but in the real business world this has no benefit at all. Actually, it would bite you later on when things get more complicated, as you would need to do the work then.
      3. "The NET is becoming more modern..." - again, I do this for living, and the company I work for as well. We are not making a fashion statement with the code. So I don't care. I also don't care for the cool dark themes people are using, or anything like that. It is an inferiority complex that forces people to do things because they look nice, modern or make them look cool in the eyes of other people. The locus of my personality is firmly inside me, not in the people around me or how they see me. Don't care about "looking" modern or whatever. So give me the efficiency, as this is what I do, not who I am. And what is modern anyways? It's just a matter of taste.
      4. "MAUI is created by different team..." - again, I do not care, we pay for the MS products and subscriptions. Give me the functionality so that I can work faster and better, and have shorter cadence of releasing the new features to the production. They should have just shifted the people working on these features, which are totally redundant, and move them over to MAUI teams and speed up the release time.
      The things are very simple here: if you are a serious developer/architects, you need to deliver a VALUE to your customer. The clients would put the hand in their pocket, pull out the money and give it to you. In return, you provide them with some value, in the form of some system that makes them more efficient, precise, faster, catering to the needs of their clients better than their competitors does, etc. This is very simple, but still many people seem to forget about this. Yes, if you can have fun while doing it, more power to you, but let's not forget what is the purpose of all this. Hence - I do not need this functionality, it is a waste of time, it slows me done, and it makes it more complicated providing not benefit at all.
      Now consider even this: Scott Hanselmann estimated 2018. that there were over 8 mil. .Net programmers world-wide. That is to say, those using .Net as their first choice. Now is probably more than 10, you can look it up yourself on IDC reports or StackOverflow annual surveys. So let's say we are all very smart and can digest all these changes in an hour: not really true, since we are not that smart as we would like to believe, and would sure take longer to swallow this, but still let's take it would require an hour just for the sake of an argument. It still amounts to 10 million hours lost world-wide for a change that is totally ridiculous and brings no benefit to the professionals, as I have explained above. Just imagine that - 10 million hours! Salary.com estimates that for just junior developers in the US using .Net, the median cost of an hour is around $29 (source: www.salary.com/research/salary/posting/junior-net-developer-hourly-wages). This means some "genius" manager in MS (or the team of them) who came up with these changes just burnt $290 million US dollars!!! Ridiculous.
      It was just a change for the sake of "hey, we have changed this".
      So for me, it all boils down to the question of how much more efficient a new feature of the language, framework, library or IDE is going to bring me? The answer for this no-namespace, no-class, no-usings, no-startup, no-program "feature" is a resounding: ZERO.
      By the way, thank you for your videos, they are awesome.

  • @runtimeterror4027
    @runtimeterror4027 2 роки тому +1

    Hi Tim thanks for the incredible work you're doing for the community. I wonder if you've ever considered covering .Net MAUI THANKS AGAIN

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      I will once it comes out.

    • @CRBarchager
      @CRBarchager 2 роки тому

      .Net MAIU is still in developement and but will come out summer/fall this year if everything goes to plan. I'm looking forward to this too and have been ever since they announced it.

    • @runtimeterror4027
      @runtimeterror4027 2 роки тому

      @@IAmTimCorey thanks Tim

    • @runtimeterror4027
      @runtimeterror4027 2 роки тому

      @@CRBarchager I’m so looking forward to that as well

  • @yazilimcibo
    @yazilimcibo Рік тому

    thanks bro!

  • @fernalag
    @fernalag 2 роки тому

    THank you Tim, great explanation!

  • @sadzio986
    @sadzio986 2 роки тому

    Hi, great video. Could You show or answer how to catch SQL Server Triggers in C# code?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      Not sure what you mean by "catching" SQL Server Triggers in C#. Triggers are just operations that are executed based upon a setting in SQL (after insert, after delete, etc.) I'm not sure what you are looking to catch.

    • @sadzio986
      @sadzio986 2 роки тому

      I mean to raise event in C# from trigger after for example row was inserted

  • @mahsasadat7153
    @mahsasadat7153 2 роки тому

    Hi Tim, Thanks a lot. it was so helpful.

  • @davidjnevin
    @davidjnevin 2 роки тому

    Excellent. Just what I was looking for! 👏👏

  • @metaltyphoon
    @metaltyphoon 2 роки тому

    The DeveloperExceptionHandler is now setup for you by default if you are in development mode. So the if statement there doesn’t even need to exist.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      It does need to exist to override that for when you aren't in development. We don't need an else statement, though, which is why they eliminated it.

    • @metaltyphoon
      @metaltyphoon 2 роки тому

      @@IAmTimCorey right, but who would put the DevelopmentExceptionHandler in production 😂

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      If you don't put the if statement for production then you don't get HSTS and you don't get an exception page. That means you get a 500 error page. You need the if statement to fix that in production (actually, for everything except development).

  • @gqntexas
    @gqntexas Рік тому

    As always, great explanation

  • @Defense89
    @Defense89 2 роки тому

    hi thx for the video im trying to logging on my db with an appsetting but i dont have any startup or program.cs , is there any way?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      What project type are you using? You should have a Program.cs file. Also, what version of .NET are you using?

    • @Defense89
      @Defense89 2 роки тому

      @@IAmTimCorey i solved it thx :) , im using dot net 6 , and i added in my data context a Iconfiguration to addjson file("appsettings"). i was using librairy classes.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      The class library will not have a Program.cs and it should not have an appsettings file. The reason why is because it cannot be run directly. Instead, those come from the caller (your UI project).

  • @StephenOwen
    @StephenOwen 2 роки тому

    Love this vid! Tim, have you done a video on easing the pain of upgrading dotnet versions? If so, share your ways! We're on 3.1 and going to leap all the way to 6.0. The nuget package dependency hell is real.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      I upgraded the TimCo Retail Manager app from .NET Framework 4.8 to .NET Core 3.1 and then again to .NET 5. Dependencies are the most difficult part. The actual upgrade to .NET 6 is easy. Most of the issues are with third-party systems, which isn't easy to cover since each is different.

    • @StephenOwen
      @StephenOwen 2 роки тому +2

      @@IAmTimCorey it helps to know that it's hard for everyone. Sometimes when I am struggling I wonder if it's hard just for me or if everyone also has issues with it

  • @akashkhan6013
    @akashkhan6013 2 роки тому

    elaborated and clear lesson as always.Thanks sir.
    Do you have any plan to make a video on the process of Project upgrade or convert to different .net technologies? That would be great. 🤞

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I walked through the upgrade process from .NET Framework to .NET Core 3.1 and then from 3.1 to .NET 5 in the TimCo Retail Manager course on UA-cam: ua-cam.com/video/Xtt6mS0p2_c/v-deo.html
      I also created a paid course on how to do upgrades: www.iamtimcorey.com/p/upgrading-to-net-core-from-start-to-finish

    • @akashkhan6013
      @akashkhan6013 2 роки тому

      Wow!! great 👍 I should have searched for it before asking. Thank you very much 💕 🙏

  • @澳贼
    @澳贼 2 роки тому

    2nd

  • @sujitwarrier4857
    @sujitwarrier4857 2 роки тому

    Excellent video as always.

  • @stephan_smit
    @stephan_smit 2 роки тому

    This is great, thanks!

  • @sahild6584
    @sahild6584 2 роки тому

    Thnx a ton

  • @bradclarke93
    @bradclarke93 2 роки тому

    Thanks!!!

  • @MechanicalMooCow
    @MechanicalMooCow 2 роки тому +2

    Would it really kill you to condense your videos slightly? You have good content, but you really could halve a lot of your videos and still share the same amount of info.
    What you say in 26 minutes could be said in 10. Your 3 hour tutorial videos can easily be worked down to 1-2 hours.

    • @MechanicalMooCow
      @MechanicalMooCow 2 роки тому

      It has literally taken 6 minutes for you to even get to the main point of the video. That's absurd. You managed to spend 4 minutes showing people how to set up a solution with 3 projects for purely demonstrative purposes. Completely inconsequential to the entire point of the video, AND anyone, like myself, that is interested in these changes likely already know the most bare bones process of setting up a project to begin with.
      Nobody that doesn't already understand the language will care about this, because anyone new will begin by learning net6 once it's current branch... you literally don't have to spend 6 minutes teaching working professionals how to set up a solution ffs.
      So, 6 minutes dedicated to a throwaway 30 second intro: "hey I'm Tim Corey, buy my courses ladida, here I have a solution with 3 demo projects, 1 is x, 2 is y, 3 is z, let's get into it..."

    • @pierreplourde
      @pierreplourde 2 роки тому +4

      @@MechanicalMooCow you don’t have to watch Tim’s videos if you don’t like them. Maybe we’re not all as smart as you or starting from the same level of knowledge.

    • @MechanicalMooCow
      @MechanicalMooCow 2 роки тому

      @@pierreplourde it's not a case of like, it's a case of respecting your audience. This video is not a video directly for beginners. It serves no purpose for people new to the language. A video like this, that is a pure demonstration and discussion does not need nearly 8 minutes of basic IDE set up. It isn't a beginner tutorial. That's like Ford, Tesla, Toyota, et al assembling a car on stage and explaining how to do so when they are there to simply demonstrate the latest model's features. It's absurd.

    • @3rd_Century
      @3rd_Century 2 роки тому +2

      @@MechanicalMooCow Why don't you scroll past the intro? I'm an experienced developer and it doesn't bother me nor do I hear a lot of others complaining.

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +16

      There is an assumption here. That assumption is that "everyone" knows what you know. Not everyone has created a solution with three projects. I try to cast as wide of a net as possible when creating content rather than "focusing" it to the point that only a select few can get value out of it. In a comment, you mentioned that this video isn't for beginners. That's not true. Quite frankly, if you weren't a beginner with .NET 6 structure, you probably would know all of this. At least, that's what I would assume. The fact that you watched this video either indicates that you are a beginner with this topic or that my assumption is incorrect. Either way, instead of excluding you based upon what "everyone" knows, I chose to create a video to help you. The thing is, I didn't just create it to help you specifically. I also created it to help others who aren't quite at the same place as you.
      So, the bottom line is that I disagree with you on what can be cut out. If I cut out things I find "obvious" or thinks that I think you "should" already know, I wouldn't create most of my videos. My philosophy is to help as many people as possible. That means covering things that some of my audience already knows. I'm ok with that. My goal isn't to have the most efficient training, my goal is to have the most inclusive and effective training.