NET Standard NET Core Why and how – Laurent Bugnion

Show video

All, right, excellent. So, as I mentioned. A few times online, it's not my first time in Hong Kong it's my first time for work so so I'm really excited to be here. Professionally. That I didn't have to pay for my flights myself for, once. But, I do love Hong Kong very much and we've had the, chance to walk around the beach yesterday and, to. Go, to pray. In the temple for the success of our team which was fun and. And. Then we went to the birds, you know, in on. The other side right there is a bird tree, the bird market yeah exactly, and that's. One of my favourite I always like to go there it. Always makes me both, sad to see the birds in the cage but also delighted to see them to hear them sing and to see the colour and everything all. Right so I'm going to talk to you about dotnet, standard net core and. So, this is a talk. That. I've been presenting. Already a few times but it's always, required, again, and again and I see it's a good thing because there is, some. Misunderstanding around, dotnet, standard dotnet core are, they the same as a different, why, should, we use them, what. Good are they and so I'm going to try to clarify that a little bit, this. Slide, is actually. Old, because. Our team has grown so much that I don't have enough space now to put everyone, I. Need to find a better way to represent. That but what's really important, here is that you can actually follow us on Twitter so we have a list which. Is pretty up-to-date with all the cloudy. Rope advocates, or I should say cloud, advocates. Because. Now we also have operations. People so if you are more into apps then, dev into. The dev ops team, right here we have devs and ops we have also an ops, team now so we have cloud operation, advocate and. So. Everybody can be followed here and of, course the hashtags, well you can find us we also have a Twitter account. Alright. So without further ado so sharing code through, through.

The Ages where did we start. So. We. Started, early. On with. Dotnet, I don't you remember I came to got Nets from, Java. And the reason why I came to dotnet is because, I, was, working for cement at the time in 2001, and. Cement, was a very very heavy. C++. Programmer firm. Right. Nowadays. They, do dotnet, a lot in, fact Simmons, is a biggest dotnet, developer worldwide in terms of number of developers. But. In the beginning you. Know he was C++, really a lot and since, I was a Java, guy they told me it's almost the same you just need to change the letters the capitals right and then it's you, know it's pretty much the same so, they asked me to do a to. Do a prototype and I started, like that in in, dotnet in 2001, so, in the beginning we had only two, client, frameworks we had for the web asp.net, 1.0. And then, we had for the desktop Windows forms okay, and of. Course you, didn't, need to. Share, across, platforms, because even if you wanted to share a library, between the web asp.net and, WinForms, he was the same runtime anyway, right he was dotnet so, you didn't have any issues, no. No need to share code really, but. Then later came. Silverlight, that's when we raised our fist right yeah. Zeolite. So. Similar, it was also I think we all grieve, and. Basically. It was however. Causing, a few issues in terms of cross-platform compatibility. Because. It was another, implementation. Of dotnet so when I talk about implementations. Of dotnet dotnet. Is a specification, all, right so you have it's like Ahmed script, if you want you, can, have in, theory and in fact in practice as well multiple, implementations. Of dotnet and they, tell you okay if you want to be a dotnet, framework you, need to fulfill those. Requirements. Okay. And so, already, at the time we had actually two implementations of dotnet we had the dotnet framework you. Know published by Microsoft, running on Windows and then we had mono which was an open source implementation, of dotnet, which, later you. Know through a lot of Hoops led, to exam arena and. So. When civil I came out from. Microsoft's. Us, developers. We had to suddenly create. Applications. With. A different, version of.net. And so maybe we had an, application which was developed in WPF like a full-blown, application, client application, with a lot of features etc, and.

Then Somebody. Marketing, would ask us can you do a companion, application that. Is going to be lightweight with, less features, but. Similar, features, and that we can distribute over the web so. That it can run easily and that it can also run possibly, on on Macintosh right so that was the idea so you have less API is a new full good net but. On the plus side of course Silverlight, was compatible with for, example Mac OS later. There was also an implementation. For Linux called moonlight and. Also portability, so it was it was quite nice nice. Feature to have, so. How did we do things back then when we wanted to share, code what. We would do is what. I would call Diplo preventively, meaning that every time that we wanted to use in. In. A class library to use an API we, would check okay is this API also available on Silverlight if, I take an example maybe HTTP, client for example in the beginning was only in the full bird net you didn't have it in in, Silverlight so, you had to use HTTP. Web requests instead okay. Which was more complicated to use what was annoying then, later in the later, version of silverlight HTTP, client came and so we, could use also HTTP, client and then we would share the files between, the. Silverlight, application, and the WPF, application, using. A feature called add as a link which I'm going to demonstrate later it's still available in Visual Studio and, then you would build why so you'd build one for the WPF, applications, one for the civil right application, and then if you had errors sometimes you had to go in the code and fix them sometimes. With pre compiler directives. Which is always annoying because it's it, makes the code a little bit dirty right but. That was away and so basically we were trying to have one version of the of, the code files and then deal twice so. That was the idea so, now still. Like, I said in Visual Studio you can add as a link so when you add an item you would go and click on the small arrow here, and then it expand, combo, box and then you add the link what it does that it's add it adds a shortcut, in the in, the project, files but, it doesn't add a copy of the file physically, on the drive I'll show that to you. A little bit later so. Then in 2011, came portable. Class libraries, PCL, okay and that was a big, deal at the time because, it was the first time that we had binary. Compatible, assemblies so instead of sharing at the code file level and building twice you, could build the project a class library add. Your files into that build once and then you would say ok I want to target, WPF. Ooh good net and, Silverlight. And later came, examine. And, later came Windows. 10 etcetera etcetera okay. I. Forgot. Windows Phone and who didn't write forget, Windows Phone so. You would select the profile, for the compatibility. And those profiles who are really very bad it. Was horrible to remember and if you think about it there are a lot of profiles because let's say that you have three. Platforms. Well. You have three factorial, profiles. Right because you have all three. Then you have two then you have the other two and then, you have one one one right so it's three bang, right three factorial so. If then if you have four suddenly, it's a lot more and then if you have five different platforms. It's a lot lot lot more so. We had really a lot of profiles and all those profiles had numbers, I remember, and, I could never remember what, is profile 57, or 68, and I felt like a failure as, a developer, because I couldn't remember that, and then one day somebody at Microsoft, intent team told, me oh we don't remember either so. I knew that it, was not too bad even, chilly but it was very very annoying so those profiles were not great so, the result that you get when you create a portable class library if, you say I want WPF, and Silverlight, you will have basically. The intersection, of the platform you will have the api's which are available on both platforms okay, then if you add xamarin, for example you will have the, intersection of the three platforms, only, the api's which are available on all three platforms, so. It is the least common denominator, approach, okay. Now, that sounds like a good idea, in fact it worked pretty well until I, would say 2016. 17 when dotnet standard started really coming out strong but it. Has a few issues you. Can still now create, class libraries, portable, class libraries in Visual Studio but, it's a little bit heat you have to search in the search box, they don't surface the, templates, in the categories, anymore and they mark them as legacy, which. Should tell you well yeah, which, you tell you that you shouldn't use it anymore, that's kind of the ID so the, idea now is to move away from from. Portable class libraries and into the net standard. So. If I summarize what I just said if you select, this is what you see when you create a portable class library you can select your platforms. And, here. If you select the full-blown dotnet it doesn't make sense to create a portable class library in fact you tell you that, it doesn't make sense because, if, you create a portable class library which has everything it, might as well create a non portable class library okay but then of course if you add another.

Checkbox, Then, it's not making sense and yet another and, then you have the intersection, of those three platforms that, you can use. Okay. So I'm going to show you a, quick demo. About. This and to, do that I'm, going to go. Into visual studio and so. I prepared two. Project. Two solutions, I should say, here. I have one with, universal. Windows. Application. For Windows 10, and. Here I have a WPF, one okay, and those, two applications do exactly the same they are basically, showing. You a text, box you can enter your name there is a button it, sends a request nasha function, it's a service API. If you want I'm not going into the details here but basically, it's just something running on Azure and so, it has exactly the same feature so, it means that I can share some code, so. To do that I'm going to go into my Windows. Version. Here, I'm going, to add a folder, let's. Call that model for example I'm, going to add a new, in. Fact here I'm adding an existing, item because I already prepared the file normally. I would add a new item and. So, if I go and take this view, model here so, here I'm adding it physically. To my project, so it means that if I go into source control I have a new file that I need to to, check in to commit but. Then if I want to add the same file into my WPF, application, I'm going to also add a new folder and then. I'm can. Oh and right click add existing. Item, and then this time. I'm. Going to go into my windows, and application, into model take this file and instead of adding it with, a. Dye add it as a link okay. And. So what it does is that you see now I have this small arrow. Which is barely visible here. Which. Says it's not a real file it's a shortcut, okay. So it has been added in the CS proj file but it's not available physically. If I open this folder in File Explorer you see that it's empty okay so I have only one version of the file now. This, technique. Is still absolutely, useful, for example if you want to share let's. Say you have like, examining application, with android iOS and, windows for employee you want to share some pictures between, those three apps but, you want the picture to be only once in your source control for, example that's how you can do it or if, you want to share I, don't know some some assets between a web, app and windows app for example you could do that as well so, now of course if I build this. It's. Just going to run. Famous. Last words right but. Normally. It should build, and then I can run my. WPF, application, and my Windows 10 app. In. A moment. All. Right it's taking a moment because it's restoring, some packages, which is always a, joy. All. Right I think it's finally. Going. To run. No. Yes. Yes finally, okay build completed. So now this is a WPF, application, and I'm going to set the, other one as. Dot, project as well like, this it can start. Uwp. Is always a little bit slower to start it's you, know. I'm. Just hacking. Math. Who worked for windows before you, don't, care anymore exactly. Everything, is in the cloud now so, basically I have my two applications. And if I enter my name here, and say please. Wait and then you will say should say hello from wrong here. We go, and I have exactly same functionality, here so, now the nice thing with this way. Of doing sayings is that if I go, into. This file and, add. Some, functionality I. Need to add a function it only once and it will be automatically, available in WPF as well in, fact there is a cool feature here, I don't know if you know this combo box here. But it tells you what, is the context. In which this, file is compiled, okay. And that's really useful because for example if here I am into Z, the. Uwp version. Of the application I can, say using Windows, for example. But. Using Windows doesn't make any sense in WPF, because, this. Is a framework, that doesn't exist here so after a while you see that now I have an error appearing.

Because Now it's trying to recompile, in, the context of WPF, so it's telling me where the error comes from if I build now will have an error but, I don't necessarily see it immediately. It, depends on the context of the file now I can see it much better so that's pretty good okay. So. That would be the shared files option. So. That's how we would do things in the beginning and then came the portable, class library so with portable class library is it's. A little bit cleaner. I would say. So. Here. I have the same applications. Three times once for Android uwp, and WPF, so, now what I can do is add a false, project, and. This. Time I'm going to select a portable class library so like I told you if you go inside here you won't find it you. Need to search for it. Portable. Here. We go they are mocked as legacy, okay there, is even the visual, basic one which is probably. Even more legacy, and I'm not saying anything here, and, then I'm going to call that portable dot. Data for example and so. Now comes the step where I need to select which platform. Is it going to run on so I want WPF, so she's not net framework full, I want, Windows 10 and I want Android, I want Samer in Android. Here. If I select summer in Android it's going to automatically, select salmon iOS as well because it's the same profile. In fact it tells you that here, below doesn't. Really matter in our case and so everything I'm showing you now you need to forget because you shouldn't use that anymore but it's just interesting to see it once so. Now if I remove this class and add my main view model just like before. I'm. Going to take it from my repo, again, it's, down there here, we go and so, now of course I need to what we call scaffold, my application. I need to wire things, together so. I will need one reference. In. My Android. Application. To. My data. To, my portable class library, ok. So if I go on the project, it's here, and then. I need the same thing in my universal. Windows platform. Application. So it's a little bit annoying to have to do that but, the good thing is that you do that only once. And. Then. If you want to add new, files into your data library it's automatically. Going to be available, everywhere so you need to do the scaffolding, only once and then you're good to go all right I'm not going to run it because it's exactly the same as before but basically you see the treat so the difference, with before is that every time I wanted to add a new file in the shared file situation. I need to reshare. It to. Add the shortcut everywhere which is really kind, of annoying and a, little bit of a maintenance nightmare. Ok. So those were our two options before dotnet. Standard, and, so. What. Did the team do what did the team decide. So. What happened is up at, some point, the. Dotnet team, came together and, said well there is a little bit of a problem with speech here with portable class library is this. Least common denominator, approach is really annoying and one, thing which is really annoying is that when. You try to add new platforms, you, risk breaking. Your project, so, think about it if you have let's say you have, WPF. And the uwp, portable. Class library, everything. Goes well and then some of your bus comes and says hey we need to support Android and iOS now so you say no problem I can add exam, array in but, then maybe suddenly your portable class library doesn't build anymore because it's. A least common denominator, approach only you have less API is at your disposal. So, that's not, really a great approach if you want to maintain and evolve your libraries okay, so. The dotnet team said okay we need to rethink the whole thing and so. They came up with an idea they said let's implement a new version of.net. Which. We will call that net core and, in. The beginning in version 1.0. They selected, only a small subset of api's that they wanted to implement just. What was needed to run some. Simple websites, okay. And maybe, some. Actually. I have that here and maybe some some. Console, applications, that you could run as utility, for example and servers etc so, it was more meant, it was in fact a project, of the asp.net team, was moment, as a. Web thing okay at first but. They started already from the start with the idea of making, it compatible for Windows Mac OS and Linux that, was pretty cool because you had an, application, that you could build and instantly, you could run this application in. That case and a web server in. Linux as well without any changes, okay, so that's pretty cool. So. Then later came. Of course the same issue as before how do we know which, api's, are going to be available because now we have the full botnet we have uwp, and then, in addition we have also dotnet. Core and so. They had the idea of saying let's not go into the profiles, anymore, what we are going to do now is a clear specification. We, are going to call that dotnet, standard, and we, are going to say okay if your application, if your framework.

Supports. Dotnet standard 1.0. Those. Are the API is that it has to support if. It support dotnet standards. 1.1. Those. Are the api that it has to support and the, cool thing is that it's always backwards, compatible, so if you have dotnet s-- standard. 1.1, it's. Going to have everything from dotnet 1.0, dotnet centered 1.0, plus, a few additional things okay. One point with everything from 1 0 and 1 1 plus a few, things so. It's always backwards, compatible, like this you know exactly what you're expecting, and, then, after that they started saying okay how do we how. Do we actually implement that, ok so we have got net core it's one thing but, then later. Examine. For example so the supports, the text, and. Author. So. Asp.net core. Well asp.net, core is atenco technically, but now with dotnet. Core 3.0. Which is going to come out at some point even, WPF, and Windows Phones are going to support the nets and hood as well okay, so basically we are at a point now where pretty much everything, supports dotnet standard, and if. We look at the platform's today already today every, one of our platforms, can. Support. A dotnet standard, class library, okay, so if you have a dotnet centered, class library, I'm going to show you later how we implement, that you can use it in dotnet. Framework so, in asp.net the, food asp.net, or, WPF, in Windows you WP, in, asp.net core. In exam or in so basically if you put, what. You had before into your portable class library if you put it in a dotnet standard, class library, you, can be. Used by everything, okay, good. So. Now let's talk about the API is a little bit and the versions because it's quite important, to understand, that so I told you that in the beginning they started, with. Dotnet core 1.0. Which, was an implementation. Of dotnet, standard, 1.0, and. They. Supported, only a small subset of api's. But. The good thing is that it was compatible, with pretty, much everything we had including, Windows Phone 8.0. I'm. Not even talking about Windows Phone 10 right I'm saying or mobile 10 I'm saying Windows Phone 8 with your all windows 8.0. Which. I think literally nobody uses anymore at Lisa at least I hope so. So that's cool so. When you create a class library, you. Need to select like a dotnet standard, class library you need to select a version ok so, maybe you start with dotnet centered 1.0, and then you say oh dang, I want to use an. API which is not available there, so, maybe I need to upgrade for example to dotnet set at 1.6 so now I have more API is quite, a lot more but, suddenly, your. Old application, which is targeting, Windows eight point zero is not going to support that anymore you cannot add this as a reference it doesn't work okay, or, if, you have done net framework you need to upgrade your dotnet for two, four six one and that can be a really issue because, in the enterprise you know that upgrading, dotnet framework is, a big deal because, you need to upgrade the whole PC and, maybe the whole fleet of PCs right so that's that difficult, and, even. Further if you go to 2.0. Now, you have really a lot of api's like they talked about 20,000, new api's now, we, have to 2.2, even so it's a little bit better, 3.0. Is going to come at some point. But. We have even more, restrictions.

Like For example for, you. WPA need to go to 16, to 99 at least or if you go to dotnet, call you need to upgrade to dotnet call 2.0, ok so. Basically what I'm telling you is summarized. In this table it looks like a horrible, table, but I'm going to explain that to you and in fact it's a small subset, of an of an even bigger table which is available at this URL, what. This table tells you is that if you develop an application. Try. To go as high as you go as you can like for example if you develop a WPF, application, if you can try to take the latest version, I think the latest is actually for 6 to now or maybe even higher. Maybe. Even for 7 right so, try to go as high as you go because then you, can add a, dotnet standard, class library implemented, with any, one of those versions because, all versions are always backwards compatible, so if you have a dotnet standard, class library, which, has been implemented, with 1 0 1 2 1 3 1 4 etc it's. Going to work into your application, you can reference it, ok. Now. On the other hand if you develop a class library, with dotnet standard, you. Should always target the lowest, possible. Version. Ok. Because, like this every. Framework, is going to be able to reference it, so. When you start with, a new dotnet standard class library start with 1.0, then. You try things out and then it suddenly if suddenly, tells you oh there is an API that you're trying to use which. Doesn't work which doesn't exist in 1.0, but, it does exist in 1.4, then. Ok maybe you have to upgrade to 1.4, but then you need to remember that I'm, going, to lose. Don't have framework. 4.5, I need to go to four six one for that okay, so try to start as low as possible and then increment as needed, or find. Workarounds okay. If httpclient is not available, maybe you have to use HTTP, web requests instead, okay. Cool. So, why. Do we even bother okay. Why do we go through all this pain well the good thing is that once, we have a dotnet core application, it, is cross-platform. And, amongst. Other thing it's running on Linux so I'm going to show you a video, and. The, reason why I did the video here and I'm not showing you live is that in, these videos, there is a lot of waiting because. I'm creating. Something and then publish it to Azure and. The. Whole demo, will take about 15 minutes but, most of it is waiting so by the. Magic of editing I reduced it to 5 minutes so I'm going to show you what happens. So. Oh yeah another thing I want to tell you is that here I'm using the command line to do that because I'm a hipster, actually. I'm not I prefer UI so I go usually in Visual Studio to do things but. I hear, that it's very hip these days, to do everything command, line so. I just want to show you that we have a lot of tools ok so you can do things actually in. The. Command line if you want you can do things in Visual Studio code. If you want that, runs on Linux as well for example or on Mac or on Windows of course all you can go like, me I prefer rather the full-blown Visual Studio it's, a matter of choice, 3 so. Here inside the command line I'm going to create a, new.

UPS No that's a bunny I'm, ready to create a new folder I'm going to change to this folder and then, I'm going to select dotnet, mu razors what does he do it creates a new, asp.net. Application. Using the razor template, and the razor template, is just a simple template. So, now I'm running this. Locally. At, localhost, 5000, and that, is the template I guess so it's a very simple. Very. Simple template, but now if I if I go into it I see that I can edit it and modify it as I want so right now it's running locally, ok, so. I stopped it and then I do git init, which, means that I'm going to add the. Files in to get. Ok. I'm going to initial get folder I'm going to commit the files. And. Then I go into the portal and I don't know if you know this, here, but into the portal we have a. Cloud, shell so, the cloud shell is basically, a way, to, interact, with your resources using a command line interaction, ok you, can do that if you're on a Mac you can do that from bash or in Linux if, you're on Windows. You can do it from PowerShell, from. The command line if you have if you prefer command or from. The, windows, subsystem for Linux which is also running bash on Windows, or, if you don't have all that no, problem you just go into the web browser you open a, cloud. Shell like we call it and then you can start interacting with, your thing so in that case I'm you're going to use AZ, which, is the azure command. Line interaction, so, here I'm going to create a, new. Resource group with the name lb, test Linux. And. Then, I'm saying ok the location should be Western, Europe because. That's closest, to my users. And. Then. Once this is done I'm going to create a. New. App service, plan so basically I'm defining, what resources my, website, is going to have like how much RAM how much you. Know storage, etc. Etc and, I'm saying okay this is the name of the plan and I'm going to add it to, my resource, group so basically it says how I'm going to be built the, SKU is this one which is the smallest billable, that we have and I say easily nukes so now I say my app service plan is already going to specify. That my applications, running they are going to run on Linux then. I create the web application, itself the website which is the web server if you want which is going to run on that so, I say ok this is a plan I want to use, this. Is name of the of. The. Web app and. The. Runtime is going to be dotnet, core 2.0. So. Like I told you right at that time when I showed the video the 2.0 was the highest, I go, as high as possible for the application, and I say the deployment, is going to be local from git so, at that point I should explain, to you that when you want to deploy an application to Azure you have multiple, ways to do this okay you can do. It the, bear way to do it is with DevOps, pipeline, so basically you set up something for example in, a, show, DevOps where you say ok I do a pipeline where every time that somebody builds. Or. Every time somebody commits I'm going to automatically, build run my test if the tests are successful I can automatically. Deploy to, staging, or maybe to testing first and staging, and production etc, here. In that case I'm choosing a pipeline which is a little bit, simpler. I would say it means that every time I'm committing, to, my. Repo, it's going to automatically, push to production very. Bad I should push to staging, but it's just to demo and, yet, and then you have also other ways to do that for example individuals video, you can also publish which. Is probably not a great idea in production, but it works as well ok, so, now this is the URL. Of my remote, repository.

I'm Not on github, I'm into, VSPs. Ok into, Azure develops, so now inside, get I say I add this, this. Remote, and I'm going to push of course the first time I need to enter. My credentials ok. And. Then. This. Part is taking a while so, this is why I speed, everything up in the Edit but, basically I'm pushing everything to get and because I specified, that into my web. App it's, going to automatically, push, it to production as, well and then I will be ready to run. Alright. So. This is the first push of course everything needs to be updated now, I'm done so now I can go and copy the, remote, URL, of my new website. And. If. I paste. It here you see that it was running so now I'm going back to, Windows I open, visual. Studio code, and. You see this is what was created when I did dotnet. New razor so for example I can go and edit, this. Part. And. Now the nice thing with this way of doing things is that now I'm on Windows right, I could run it on Windows who test it on Windows but now if I push to. Get, to. A here it's. Going to publish it and now I know that in Azure it's running on on Linux. I test. On Windows I push on Linux and then it just runs because. Of the magic of asp.net core, so basically if I go into the about page we see that my change was published, okay so. Of. Course, this is great because why. Linux on most of the web runs on Linux okay, it's cheaper, it's quite, reliable, not saying that Windows servers are not reliable, but you. Know it's probably even more reliable, and also a lot of. Website. Administrators. Know Linux very well and so if you want to hire a new, person, chances. Are that they, know Linux pretty well so like this you give them the choice basically you say oh I have an app it's. A dotnet core if, you make me a case I'll push it from Windows to Linux and, we're okay with that and, it's good for us on either anyway, because we have Linux as an offering so we're happy to, welcome everybody.

Okay. So that would be the. Reason. So. Let's talk about portable. Class libraries, versus. Dotnet. Standards and to, do that I decided, to show you a real life example so. For. Those of you who don't know I am the creator of popular. Toolkit. Called mvvm, light and. It's. Quite popular since, 2009, where, I publish it I had something like three million five, hundred thousand, downloads so it's used quite widely I would say and it's, used to build applications in WPF in, Windows 10 back then in Silverlight of course and also. In, exam room so. The. Architecture, of the project, was like that, so. What happens here is that when, I created the project in 2009, I created it only for WPF, at the time and then very fast I decided to add sea of light to the mix so. I did that when, civil like two came out and. It. Meant that I had two projects, I had one project for WPF, one project for Silverlight. And then, later examine. In came, out and I decided to support that as well and. So I had three projects, and then. Windows. 10 came out and I had four okay, so it started to grow in a bad manner it, was really annoying to maintain, and at some point I was lucky that the. The. Team who. Created the portable class library who was, the. Ah what. Are they called now the. People who did prison. Patterns. And practices what. A PNP, exactly. So the patterns and practices team which are at the origin of portable, class library reach, out to me and asked me if I were if I agreed for, them, to take mvvm, light and, to put it to, create to convert. It into a portable class library and the, reason why they wanted to do that is because they wanted to take a framework which was already widely, used, but. Which was not overly, complex and try. To put, it as a PCL, and I guess it would learn from the experiencing. What, doesn't work and you, know what do we need to do better so. I was really happy to. Hear them propose that because it's free labor so I'm always for that right and. Plus. They knew what they were doing I didn't so that was really good and. So, my. My good friend already Novotny is actually the guy who did most of the work this guy's a genius if you don't know him, he's. Also an MVP, and he did most of the pot he had if you go and check the source, code on github you will see that there are a few places I, can show you if, you're interested there are a few places where he had to do a few workarounds to, make it work but. Basically he, managed to put, everything, into, a portable class library which is pretty cool so. I have the following, of architecture. As a PCL, I have what. I call the core component, which are in 2d. Ll called galas of the time if I am light and then. I have, at.

The Time I decided to support a, new ID from pattern set practices, which, is called common service locator so that. Sounds like a great idea, it. Was like kumbaya. Everybody, is friend huh well. Basically they say okay back then a lot of people are raising something. Called ioc containers, so who doesn't know what an IOC container is, don't be shy I'm going to explain to it if you everybody. Knows you're sure, kinda. Okay yeah. Somebody, okay good. Courageous, person, so. Ioc, container basically. There is a pattern called dependency, injection, okay, where you say okay in. In short ioc container is, a little bit like a big cash okay. So into, your education you have a global cache where you're going to save some. Some. Classes, some instances, like for example let's say that I want to have, I. Don't, know I want to have a client, for for. An API okay. Let's, call it data service, for example so, I can have an implementation of my data service, into my cache into, my ioc container and, then from everywhere, in the application, i can say get instance, from my cache and I can use it so. Why do I want to do that it's because the nice thing with ioc containers i can also abstract, the, client, i can say in, self care of saying get instance, of data service, I say get instant of I data service, and then. When, my application, starts I'm going to register I'm, going to say every time that somebody asks for an i data service, please, give them a data service but. Then I can have also another implementation. For example for uni test I can, have another. Implementation, which are called test data service, which also implements, a data service and then, I say every time that somebody requires, and I date a service gives them test, data service, not the data service from production, but the test okay. Now, for the consumer, of the IEEE data service, he doesn't know and he doesn't have to know that the beauty of it okay, you're, just going to call whatever, method. Is defined, by the interface, by the iData service interface, but. You don't need to know what. The implementation is actually going to do that. Can be very useful for, example if you have cross-platform. Applications. It's a great example let's, imagine that, you have. Plugin. Which takes a picture okay, taking, a picture on an Android device is not the same at all as taking, a picture on an iOS device the api's are completely, different so, in exam or in what we do is that we do. Media. Plug-in we call it and then, this media plug-in is going to have. An implementation on, Android which takes a picture in the Android way an implementation. On iOS which takes a picture in the iOS way and then it has an interface a, definition. Which has a method, saying take picture with a few, common. Parameters. Okay, and then, after that when you take the picture in your examine application, you don't know if you're on Android or on iOS and you don't care okay. You just take the picture and that's it so, the. Ioc. Container is, very useful for these calcine Aereo's or also if you have things like unit, tests for, example in unit tests we try to avoid, calling, actual. Websites, because. If you want to test I. Don't, know you want to test an error and then you have to call Google to say can you please shut down your website for a moment just, because I want to try things out and you know create an error it doesn't work right so in that case you create a test client and you, raise an error, okay. So long. Story short, everybody. At the time was creating, their own ioc container so, you have multiple, ioc containers on the market when you do that net you have one. In mvvm, light food simple ioc but, you also had one in i don't know one called auto fire cause every unity, not unity3d, another, unity, prison. Has one etc, etc so there was a number so. Patterns and practices said hey we have a good idea everybody's. Friend if, we, decide. To, switch. An ioc, container with, another one it would be cool if they all implements, the same interface, like. This and the changes, into my application who, are going to be minimal okay. So. We are all going to implement the so called I service, locator which, is contained to a library. Called common service locator and like, this everybody's, everybody's. Happy, sounded. Like a great idea I said okay my simple I will see my ioc container is, going to implement that as well and that, was, really a not very good idea with say it's still, causing me headaches these days mostly.

Because It's a dependency, on a third party component that I don't own okay. This is developed by another project altogether. By. Another, team all together so. That the first thing also the other thing is that it's really solving. A problem it's. A great solution to a problem that doesn't exist now. That's what I call it because. In fact how many times in the lifetime of an application are you going to swap ioc. Container probably. Zero okay. Because you all have an IOC container that you prefer so, you're going to use it and maybe. Once okay but for, for just one time this whole effort is not worth it. So I was not super happy with comment service locator but basically that's what I had and. So, in addition to those libraries. I also have some platform, libraries so I have some components which are only available in Android I had some components, only on iOS for example data binding, system in. Windows I don't need it because there is one already but, in iOS and Android I implemented one I have, some components, for dotnet 4 5 etc so. That the library I have and the. Landscape I had before I put into the net standard, so. Now comes the time of refactoring, which is a great time because you can fix. Errors. That, you made then the first error I wanted to fix is get rid of command service locator ok. Know. Come by anymore. And. Like. I said multiple, reasons first reason, it's. Really a dependency, on a project I don't own it's really annoying because every time they upgrade, the version of here it breaks my stuff so it's, really causing me issues they, took it down they. Know. It's you exist and it's somebody else added another version yeah I know it's crazy right and then now I have issues and. Now I have issues with that as well and so I'm probably going to release a new version of of, the portable class library without that at all anyway. Cool. So I want you to remove that from the dotnet standard, version now that would be a breaking change but. I'm ok with it because I, would say the port from PCL, to dotnet standard is a step which is big enough that. I can introduce breaking, changes, if I document them enough ok, so. Now if I remove command service locator I don't need those two dll's anymore, why. Did I have to dll sian tell you the story this is also very complicated when. You have a project which is widely used you, encounter, all kinds of weird, requests. Like. For example once I had the call from a firm who asked me to feel people work so that their developers, could use my open source project, I said no well, I didn't say no I said yes but for 500 bucks an hour and then, they said yeah but your project is free I said yes but my time is not right so, ok. So I didn't do that but basically procurement. Is hating, when you have more than one DLL into a project because. Every. Time they have to feel and Siemens was like that right every time you have to fill some paperwork for every component. That you pull and so if I go back here, here I had one here. Which, is Gala soft okay that they could talk to but then I had another one which I didn't control which, was in addition so I did I separated. This dll like this if they decided not to use that they, could still use this but. They didn't have to use that does that make sense okay. So. Now, since I remove, the comment service locator I don't need that anymore so I can I have only one DLL so it's way easier for me as well and then, of course there, was a problem of the platform dealers because they had the reference on the portable class library so, I need to change that so I have another set of those platforms which, this time is called standards, and.

Basically, That's my new landscape, which is a lot easier okay. Cool. So now what I will do in front of you is show you how how, I taught it from my portable class library version into. My da 10th standard version and you will see that it takes literally just a few minutes, so. This. Is the. Amelia Nye project, on github. That's. Exactly. What I have on github right so. Now this, is already supporting, dotnet standard, but if I go back in time. Approximately. Two years ago or, three years now my good time flies, this, is the last version before, i ported, to dotnet, standard so i'm going to go and check this out. Which. Means that basically i'm going back in time three years ago okay. So. Now i have a version of the application. Which. Super version, of the class library i would say which, here. You, see that it still says vs, 2015. Because back then that's what we had okay, we didn't have 17 yet i'm, going to open it in 17 anyway because i don't have 15 installed, which means that I will have a I'm. Recorded. So I will have a lot. Of errors I was going to say. Something. Exactly. So. I'm just going to say okay a lot of libraries. Which are inside they are not supported, for example I still have the civil right five versions into, there this, is of course ID, alright this is not supported, anymore. No. Problem this is just telling me the. Report, so now you see if the, architecture. That I showed you before so, I have my test I have, something, for dotnet three five which of course is not available here now, this is a portable class library that I mentioned so this one is going to support dotnet four five is supporting xamarin it's supporting, you, WP. Etc. And. Here, I have the the, other one which is called the extras, and the extra heads on easy ioc container that. I mentioned before and here I have the reference to Microsoft, the practice is the service location that, the common service locator that I mentioned before okay. Good. So, now I'm going to convert that and those are the platforms libraries, you see that I have a few for, each platform I have some components, which are platform specific, alright, so, let's create a new portable, class library well, actually a new dotnet, standard library so I'm going to go to new project and, now. Here into dotnet standard, okay, so don't confuse dotnet core donate, core is a reminder that the application. And dotnet. Standard, is a class library, now. To make things easier, clever. People at Microsoft decided. That you would have also a dotnet core class library, don't. Use it. Let's. Say it simple don't use it it's, a bad idea okay. So, we will use now class library dotnet standards, now. I'm going to create that. Let's. Call it galas, of. Dirt. Mvvm. Light, dot. STD, for standard for example I'm, going to create that and. Now the very first thing I'm going to do when, visuals. When you create a new class library it's, going to try to default it to the highest. Possible, version, of the framework but. I told you it's bad right we want to go low we, want to start with 1.0, so, let's do that I'm going to change that into the properties, of my project, and, here. I'm going to go to 1.0. Okay, I'm, going to try if it works right if it doesn't work I'll go to 1.1. Good. So now this is done, let's. Remove this class and so now what I'm going to do is basically take all my classes, from, my PCL from portable class library and dump them into my dotnet center then I'm going to try to build because, what what.

Could Happen really. So. I'm going to take everything. That has class files. Now. Here I'm going to copy them in, reality, I would add them as a link because I don't want to have two versions of the files but that takes longer so here I'm just going to copy them. Here. And. Now. That this is done I'm going to build. It's. Going to take a moment and unsurprisingly, I'm, going to have some errors because. There are a few things which don't work. That's. Normal, so. Let's. Wait and see what's, happening. And, I can already tell you the first error I will have is because I'm using. Somewhere. An. API, which doesn't, which exists only in WPF which doesn't exist anywhere else so, this is going to cause me an issue and you see that what it says here it says the. Type of namespace name message, box result could not be found so. That is correct, it. Doesn't exist, except. In WPF and, in, fact I knew that and. I already told, my, users, long, ago that this class is obsolete now you shouldn't use it anymore so. Now that I'm into dotnet. Centered, it's really a good time to just remove it so I'm simply going to remove that class it doesn't exist anymore okay. People, have been warned now, hippos are errors the. Next one is the, type of namespace, shredding doesn't exist that's weird because I'm I know for a fact that shredding is there so, what's happening here the, problem. Is that the, clever people at windows decided. To change namespaces. Oh, I. Know the oh nothing windows anymore. So. When they created, UWP, they said hey instead, of having systems of Windows of threading we are going to have windows that you had example, because it's almost the same right now that I think that the core ID threading is in the core probably, so. In, a, sense, internet, standard, they decided, to follow the conventions, of the, Windows 10 version, of.net and, so, if you want system windows of threading, it's. Actually in two windows UI core so, basically what it says you see I was already prepared here, I said if net, ethic score if I'm using Windows 10, you. Should rather add, those. Two if, not if I'm on WPF, you should add those. Okay so, here I'm going to tell my dog net standard projects that it should follow the convention.

Set. For, Windows, 10 okay. Now. If I build we will have another one of those errors. And. This. Error. Comes. Also from some namespace definition. It. Just takes a second to rebuild. All. Right and so the last one is this windows here which is not available. Because. Not only I have to follow the dot the net ethics core definition. That I also have to follow the portable, class library definition, so, basically there are some native species which, are which. Have different name which is a little bit annoying once. This is done basically. My code builds so you see that it was not that big a deal okay, so. Now I have all the core component, have been ported to the net sender that's cool, but I see I have the ioc container remember. So. Why don't we do that so now I'm going to go to the extras. I'm. Going to take here, this. Folder copied, there now. I'm going to do the same thing again I'm going to rebuild that. And. Like you would expect is going to fail again. Is. It rebuilding, it's not rebuilding why not. Rebuild. Oh, it. Already failed. It. Failed because, Microsoft. The practices, that service occasion cannot be found that's correct that the comment service locators that I didn't add so, I'm going to remove it which. Means that I cannot, use this, interface anymore, that's, a kumbaya interface, the. One that if you implement everybody, can swap your ioc. Container and, be happy hearing, that yes I see no I hate happiness, let's. Remove it okay and, now I still have one author, here. And, what. I did here is that I decided to use this activation, exception, which comes from the comment service locator, library. And so here I need to replace it with something else I decided to replace it with invalid, operation exception, now. This is a breaking change right, if you are somebody who who. Catches a activation. Exception the a code is going to fail but then they go to a medium like dotnet they find the documentation, and they know why and no. Problem okay so I, just need to replace it I, have a, few. Of those. Okay. And now I can build and now it's going to run so. Why. Did I do that again, right, well now first, of all I have a dotnet standard, version of mvvm, night which is good because. Some, people, we're. Already building some, applications, with. Dotnet, standard class library and that's not least they have to add a PCL, library. And then there was some compatibility issues, so. Now they have every single dotnet standard way better. Another. Cool. Thing is that now if you create a new. If. You create a new, examine. In forms, project, for example so, if you go to, cross-platform. Mobile, app. Create. Examining, forms application. You, see the dotnet sharing, strategy, now they don't use PCL. Anymore they use dotnet standard, so, that would be the project in which you put your UI and your shared code in xamarin which then later runs on iOS Android and Windows, so, when, you use Dameron, you want to have every single net centered if possible it makes life really easier. But. Also it. Means that now you can use mvvm. Right on linux as well and in fact why don't we do that so. I'm going to go and create a, new yes. Yeah. Absolutely so. Yeah. So. It works because, basically. Dotnet, standard. Translates. The, call right so, sorry. That's, floating, exactly, so, basically what it means is that it. Knows, that when you call in that case the system that's reading is there for the task, class okay which is super important when you do a sync and wait so, every time that use the task class in WPF. Good net sender is going to translate the call to, forwards a call to the system that windows a trading library. Which is running underneath and, so, that's basically. The beauty of it is that it is abstracting. The differences, between the platforms. So. Not. Exactly so. Here, we. Have to differentiate between applications. And libraries okay class library so when you do an, application. And.

You. Have in, your application support. Which WPF, doesn't yet by the way right it will with dotnet cost 3.0. But it doesn't yet, supports, dotnet, Center it doesn't, implement dotnet, standard yet right, but. You can use, dotnet. Centered class libraries, already that, works okay, because of the type forwarding thing so what it means is that if I have a WPF, application, and I have a dotnet. Standard, class library, like, mvvm, light I can use it ok what. It doesn't, yet it's, not an implementation. Of dotnet call 1.0, now of dotnet standard 1.0, 3.0. Sorry why is that important, so I I. Do just a quick, side. Here. So you may have heard that WPF. And windows. Forms I mean to support, dotnet. Code 3.0, what does it mean. Unfortunately. It doesn't mean that magically. You can develop a WPF, application, and run it run it on Linux ok, it doesn't mean that and the reason why it doesn't mean that is, that there is no UI stack, currently, which, runs both on Linux and on Windows so. The UI is the issue here, okay. So. It was not really developed in terms of cross-platform, compatibility, but it has a really nice feature however, it. Is that dotnet core versions, can run side by side on Windows, so. If you have a WPF. Application. And you. Say ok this WPF, application, is running on dotnet core 3.0. You. Can run it but then if you have another one which is running, on dotnet called 3.1, in a year for example you. Don't need to, upgrade your PC, to dotnet core 3.1. Anymore the. The application is going to contain everything you need so everything is going to run side by side now in, the future I don't exclude, the possibility that. We will have a UI stack, which is going to be Universal as well I don't. Know that it's. Not Microsoft speaking here it's my my hope okay. I don't, know if that coming I have no clue nobody, knows but. That would be cool though I'm not sure how see how it would work to be honest because I, mean example already. So. Yeah. Exactly. So so so, here for, WPF, and W and windows form running on dotnet cause 3.0, the beauty, is not really the cross-platform seeing, the. Beauty is that you can have now side by side multiple versions of.net. Core. And when you don't you don't have the problem of having to upgrade your whole PC to a new version of.net anymore, so it is a progress. Yes. Yeah. Because the dotnet core engine is way faster than anything, we had before especially. They did huge performance, improvement, because of the web especially because on on website. You you are rated, I mean, the competition is huge right with other engines, like node or others, and so, you need to be fast and so they they made it fast which, means that on the desktop we are going to basically benefit, from that automatically. For. Torture. So, it's. Not an implementation. That standard, class, library, but it has metadata. But it's called a tight border, so, what it'll do is it'll point to the API that's not implemented, in the. Metadata, and say. That basically if you ask for this namespace, go. To that namespace and. So, it makes the, metadata, point, to the right implementation of, the API so. Even though it's not implemented. When it's pulled into the. Platform that has systems not threading, when, it makes a system that threading call it'll, so forward to the correct name space within that class. Pretty. Clever right. Cool. So. Yeah. So. What. I wanted to show is that now that i have nvidia night on dotnet standard, right i told you a little bit the advantages mostly, was compatibility. With other people who are already using the net centered but. Now what i can do i can go to dotnet, core so this time I'm going to dotnet core because I'm going to do an application. And. I'm going to take a console, application I would love to create an application with UI running. On dotnet core but unfortunately, that doesn't exist I'm going to do a console application instead, and. I'm going to call it core, with, them, the light, for example, okay.

And. So, now this. Time I'm doing an application. So. I go as high as I can okay I don't need code 2.1. That's. Cool because. The. Platform, that i'm going to run it on i'm, going to run it on ubuntu and on, windows those support. Dotnet. Co 2.1, in, the past when i started, giving this presentation ubuntu. Was supporting only dotnet, code 2.0, so i couldn't go to 2.1, i had to go back one but like I told you you start high with for applications then you go backward for, class library you start low and then you go up ok so here I select, that and code 2.1 I'm good so. Now we are going to build old-style. Old-school, console. Application, right, so. First of all I'm going my console, application, let's imagine that it's a utility which needs to communicate with Web API somewhere, ok and then let's imagine that I'm going to run this on servers. Periodically. And make sure that something is happening ok so. I want to do things cleanly, so I'm going to add a new folder call. That module then. I'm going to add an interface. Add. New. Item, and. I'm going to call that I, data service. Alright. Make. That public, and. Now this I data, service, is going to have one method. Called get result, now, this method, is going to be a stupid method, which is basically getting, two integers, asking. A natural, function to give back the result of addition because. You want an Asha function, for that, let's. Imagine again. Let's, imagine that this is some doing something meaningful such. As I don't know getting information from an API and returning, that okay so, that's my my interface so now I will have of. That. Can be string in that case it doesn't in my application it doesn't matter here. And. Then what it returns is basically the function says the, result is and then the result so I get. The string back. Actually. No it's not true it written some JSON in that case sorry, no it's written some JSON that's why I get some JSON and then so my idea services returning the JSON okay, I have. Multiple functions that I use in different, presentations. Okay. So now I'm going to add an implementation. To that so let's add a new class. Data. Service. Okay, and this, implementation.

Is. Going to implement, a, data service. And. This. Is going to say okay in that case I'm, going to connect to a URL, this, is the URL of, the function, notice. That it's taking two placeholders, num1, and num2 so, the first number and the second number and, then. I'm. Going to use an HTTP, client. To. Call get. String uh sync which, is a synchronous so I need to make this a sync and. I'm, going to take the URL replace, the play at the first placeholder with, the first number that I'm getting into my phone into my method and the, second place holder and I'll return whatever comes, back from the function super, simple but of, course here I'm using HTTP, client so if I want to test that for an employee in a uni test that, could be an issue because, maybe my service is not running or. Basically. I want to have known conditions, into an HTTP, into a unit. Test and, calling. Nadja functions is not this, is not a known condition right maybe, the. Data center is down for some reason so. In that case I'm going to say okay I'm going to plan, to. Have another implementation. Which. I call test. Data. Service. And. This. Is also going to clément the same interface. So. Basically what I'm doing here I'm coding. What I told, you before about the ioc container that. I have two implementation. Which all fulfill, one interface, and, this, one is going to say every, time you call it is going to say i don't know how to count i'm just a test program basically. It is a known value okay. I'm getting something which I know all, right so. Now I have one. Interface. With two implementations that, sounds like a good scenario for, an IOC container okay. So, here in my program, into my console app I'm going to say first of all I'm going to ask the user what. Do you want to do do, you want to use a test service or the real service. I'm. Going to get the. Result if the result is one I'm. Going to say all right every time that somebody asks for an i data service, please give them a test data service, and then. In case the result is two every. Time that someone's I asked for an eye data service, please give them a data. Service all, right now, of course to do that I need simple, OC, so. The good thing is that time into an A into, a dotnet core application, I have a dotnet standard, version of the simple IOC I just created it before, so, I can go and add a dependency, now in reality I would go NuGet and pull the dotnet standard, version of mvvm. Light but, here I'm just going to add a reference. Go. And browse actually, I have it here already because, I you. Know I tend. To try, my demos, before I go, to. Talk, to a group of people so here I already did that before so. Now I have access to simple IOC all, right this is good, now. I'm going to get the two numbers that my, user wants to to. Use so first operand second operand and I'm going to compute, and so just to make things a little bit more interesting, I said I'm not going to do the, call here but. I'm going to go into another part of my application so in a real application you, have multiple components and then in one component you ask things from the user in, another component, you run them you know so it's, kind of decoupled.

Okay And so here the beauty is that I can say here I have simple, you see where I register. My data service. But I'm going to use it into. Another class, which is here, and here. I'm going to say in this class I'm going to get, the. AI data, service. From. Simple IOC I don't. Know what I'm getting I don't know if I am getting a. Test. Data service, or a data service here in this particular class in this particular component I don't care I'm just. Want to call get, result that's all that, matters to me okay, you. See the decoupling right so that comes the ID so, now I'm on Windows I test. My application, yes of course I'm going to press ctrl f5. Okay. Let's. Try it so let's do, two. For the real service I'm going to enter 30, and, 12 and of, course the result is. After. A short wait. It's. Not going Oh the result is 42 which is correct because it's the answer to life the universe. And everything, in. Addition, I get an information about the time on the server because why not. By, the way you should, know that, this. Is interesting why is it in February. 1900. Day right oh yeah yeah. Yeah sorry I'm a little bit confusing. Times old yes. It. Is yes exactly thank you so, it's V it's working fine good so now let's try things again, but. This time with, the. Test, service okay so enter, this, and now it says I don't know how to count I'm just a test program my application, running so. Now your boss comes and, says, hey you have this cool windows. Utility that. Is running great but, now we are putting all our servers on Linux can you implement a version of that on Linux and you say yes I need six months and, then, you do it in ten minutes and you takes five. Months and the. Rest of vacation, which is great because, basically you already did the work this is already a dotnet core application, right so. In order to run it on Linux, I'm. Going to go and click on publish here what it does is basically it just gathers. Everything, needs to run them I'm going to publish to a folder. Which. Is here, so basically it's building, in release mode. And. Now. That it's done I can go to my folder, if I go into bin. Really. Is dotnet.

Corrupt To one publish, you, see that it has everything it needs it has my dll, it. Has galas, off the ten Vivien I dot s T V dot DLL so basically everything, I need to run this application so, now you take it I'm going to put it in C just so that it's a little bit easier to access and. I. Can try on Linux so here I'm on Windows the, cool thing is that on Windows I have whoo boon to that, I can run so. I don't know if you're familiar with that this is something called the windows subsystem for linux. Basically. It's not an emu it's not an emulator right it is actually Linux running on Windows. And. Here. I have installed Ubuntu so, if you went to the Windows Store you have multiple distributions, that you can get depending, what your prefer, personally. I like one two so here I'

2019-02-27

Show video