James: 00:07 Frank, can you guess what I purchased? Frank: 00:11 Ooh, wait, that sound, oh my God, that sounds James, you know, I was just at the living computer museum, so I actually know that sound that is a 1980s keyboard. Why would you buy a keyboard from the 1980s? James: 00:26 Well, you know, it was a glorious time in the 1980s there was a lot of great individuals being born around that time, especially around 1986 so, you know, Frank: 00:35 hmm. I can't think of any, but we'll just assume that there were, so you got some kind of passion for the old clickety click hi you. You fell to the ideas that the internet saying that these keyboards with, they're like eight inch key travel is somehow superior to modern keyboards. James: 00:53 Uh, yeah. So I, you know, all the cool kids have the mechanical keyboards and I was watching this youtube video of like, hey, great products under 50 bucks. And I was like, Hey, you know, I'm kind of sick of this Bluetooth keyboard. Let's give this a go. And what I like about the mechanical keyboard that I have, it's from check where it's the Phantom Rgb, backlit mechanical keyboard. Frank: 01:15 Ooh, I am pro backlight. I love backlight. And especially I think if, if I'm imagining are these like the really like rainbow, we ones programmable. That's the best part. Nerve. Now whenever I tap James: 01:30 been a key it like lights up based on that key and like does sparkling effects throughout. But you can have a just the rainbows and waves and sine waves and Grambling rave if you want to. That's the best part of it. Yeah. Frank: 01:41 To be honest, this is the end of programmers civilization right here when we obsessed. No, I take that back. I think we're all in this business because we all obsess over hardware. If we think about it really hard, so I'm not going to make fun of you and just compliment you on your clickety. Clickety clickety aren't you okay? The rainbow I love, but don't you think you're going to get annoyed with the eight inch key trefle James: 02:04 well, so far, yes. This is my, I bought the about the browns. The Cherry browns. I don't know what that means, but there this one's supposed to be the in between where it's not as cliquey as it could be, but I will say it is very different to type on this keyboard because the keys are very large and the key travel is very high. Now that is not my podcasting keyboard because I hope not. I don't want to type on the keyboard and they make large sounds but it is my programming keyboard. So we'll see when I do some twitch streaming, um, on Friday if people love or hate it and I have to go back to my low key travel where the keys are so thin that it doesn't, you can't even feel it basically. So we'll see. Frank: 02:55 I'm going to make a prediction here and say it's going to be good for twitch. Actually know how like all the movies make the boot beauty beep sound when people are working on a computer. I think it's a more natural version of that. So I think it's actually going to work. I think just characters coming out of the blue is kind of weird. And I think having that click associated with each one. So it's either going to be annoying, but I don't think it's going to be annoying. But this is all hilarious cause I'm on a Mac keyboard that like has, you know, a billionth of a millimeter worth of travel for each key. So like in the Mac world we've been getting tighter and tighter and the pizza world's been getting click here and click a year. So James, I was reading the tweeters and a tweeter came up and I think if I'm reading this right, you are betraying us. Frank: 03:40 James. I accuse you. Do you want to hear your a accusation? Yeah, bring it, bring it. I need to know. All right, one Twitter out there named Brady. Gaster says that today he learned that Jane's Mountain Man, Y'all changed his mind about dependency injection and an inversion of control as he observed the magical future of wow con drawn. It's a funny name, Huh? But James, what's going on here? Dependency, injection and version of control. Then weren't we just talking for 8 million episodes that we don't like those? Yes. For 145 episodes, frank, nearly three years. It's all been a lie. Little did you know that? Deep down in my heart, I actually loved now. Um, so, okay, let me, let's, let's break this down because even, and I, before doing the podcast, we're a little bit like there's Dui, there's like service locators, there's IOC, there's constructor injection, there's all of these things, you know, out of there. Frank: 04:43 And even I get confused on what I love and what I don't love. So how do you interpret dependency, injection and inversion of control because those are two different things. Yeah. Okay. So let's get into some definitions here. But I think that the last time we talked about this, we both agreed that we both liked services. So maybe we should kind of start with that concept. So, uh, an inversion of control, instead of putting all the logic to say, make http requests or, uh, you know, do this or that services, things that, uh, business logic, big things that your app needs to do. And you have some layer between your Ui and that well you cannot put that logic all into uh, like your code behind or you can refactor it out and if you refactor it out and to services, you can um, make use of those in your own classes. That is a terrible explanation but that's how I think I inversion of control is I'm refactoring out things into services and then I have one class that's kind of joining them together to do something useful now as bad mean that up a little, the, the, the entirety of it. Sometimes it comes from James: 05:58 interface based programming where you may have sort of that code broken out. I like to think of it as here's my, you know, web, backend service, but maybe I have a mock service. They both implement the same interface and I want to wait to say give me one of these things that I have created and I will use it. So your code behind? Yeah, it doesn't know about the thing. It just knows that it's going to get a thing and use the thing. And the service locators we like to say usually have the option to get back the same instance of it. So you don't have to new up new things all the time. And that's one thing that's nice with the end goal being, I can easily say I can change the code in this one little thing or swap it out with a new implementation and the rest of my code doesn't have to worry about it. That's kind of the goal I think. Yeah. Frank: 06:46 And that's the second part of what you've said, that it was the dependency injection. So forever, um, I've broken my app up into services and kind of naturally you do interfaces just because, well, honestly I usually like write a really bad version of the service at first. Some people call those testing versions or mock versions. I call it. I'm just kind of being lazy and I'll fill in the details later. And so you naturally like breaking things, break these things out and interfaces and that helps for testability and everything. But the real, uh, um, the second issue is okay, if it's a bunch of interfaces while someone's actually got to create some objects. So who's responsible for creating the objects? If your code behind creates the objects, then it's locking in the tight. And we don't want to lock in the type. We want to use interfaces. We want to be flexible with the actual object that gets created. And that's why we have what you are calling us service locator. There are so many names for this. I think container was one of the original names. Yeah. James: 07:48 Yeah. Container Service locator, dependency service. Uh, that's the Xamarin forms version of it. These all are very simplistic. Uh, usually some are more heavier because something, you know, at the simplistic form you could say, here is this class and when I want this class back, create a new version of this class. Yeah. Frank: 08:15 Yeah. And it's funny, like when I would do this myself, I always thought why would I use someone else's container or object or something like that. But what eventually occurred to me was that this dependency injections, not actually so simple. You can very easily have a, that depends on be, that depends on c and oopsie dupe. See I made see depend on a, now your program can get very complicated and resolving that dependency graph is not trivial and that's why even though I'm totally a not invented here person, I tend to use other people's code if I dependency injection. But maybe we should get back to um, in the past, I, I haven't used it that much to be honest. I've used it in Xamarin forms and I've used it in asp.net. How about you? James: 09:08 Yeah, so when it comes to that inversion of control, service locator, model dependency service, I naturally enjoy using that model. I think that the, what I've always liked about doing interface based programming was the swap ability or even if you're not using it, just saying like, give me this thing and I can reuse that a good, a good use case. Be like a lager, right? I have a lager, I might have multiple types of loggers gimme the logger that I want, you know, and I can change that implementation and you want to use that same logger all over the place and using the service locator or dependency service model, you in the past would basically say public static logger, new up your logger and then that static everywhere and you don't want a static everywhere. You don't want a new it up. So this thing just says, hey, I can at anytime anyone could be creating a different logger and I'll just get that back from me. James: 10:09 So I've been in favor of that simple model as long as the platform itself supports it or it has it built in. So when I did core Ios or android work, I don't believe that I really ever use anything that was from Ios or android. I believe if I go back in time, there was a very, very old standard service locator that someone on the Xamarin team wrote once and I copied and pasted that code into every single one of my projects. And it, it didn't do anything. It, it just did like here's a class, give me in the class or here's the interface for the class. It didn't do anything else. Right. I did the bare minimum and that's what I liked. Frank: 10:54 So what's it all singletons then? It was all singletons. Yup. Okay. Yeah. So I think that's what originally kind of turned me off actually from dependency injection. Um, I come from the old school of we don't like singleton objects. Every object should have a direct point or to the thing it's doing and you shouldn't be looking to the global namespace. And that's what we're talking about here. We're creating a global namespace for objects. And so, you know, we use that term, my code smell. It wasn't like a code smell to me. It just, I felt dirty though. I totally did just because this concept of this global namespace bothered me. But then, um, when you think about how you in practice actually implement it, the most common pattern you see is, um, I have, uh, I have an object that has some dependencies and in the constructor of that object, I just list out all the dependencies. Frank: 11:49 And the form of, I have an argument for every dependency and every one of those dependencies is most likely an interface. It doesn't have to be an interface, but probably an interface. Uh, and then in the constructor, that's when you asked the container or service to, um, I'm sorry, you can either have the service create one of those for you or, and this is the part that made me feel like it's not singletons anymore. You can just create it yourself in that class and like a default constructor. It can be a field, it can even be a property so you could swap it out later. And I think that's what finally convinced me. It's, although by default we keep making things singletons and globals. It really is just a default. And if I'm, if I want I can override it in each object. James: 12:35 Yeah, there you go. That makes sense. I, I use the, the Xamarin forms one kind of added on to that one. They have a dependency service and they, I like to call it an MVP. So like minimal viable product for a dependency service, which gives you the ability to register those things manually. You can also do x assembly exports, which we'll do assembly scanning, which is kind of Nice but may have some overhead. I'm not really sure either way there. It's really quick though. I know that the assembly standing is, or um, what you can do is when you get that thing back you can say, give me the singleton version of it or create a new version of it for me. It's not giving you maybe the flexibility as much as what you're saying, but it's somewhere in between. And I started to use that because it's built into the framework. James: 13:29 Like that was one thing that I always appreciate it you said about asp.net or Xamarin forms where it's part of the framework where if you're doing, you know, normal like desktop development or even android or Ios, it's not, you have to go find another package. And this is where the auto fax, the unity's, the, the prisms and the Mvvm left and the maps and the, all the things come in. And I'm not against them. Right. I love, I love everything. Maybe not math, but like I love everything, but you know, and, and for me it was, I don't want to have to go all in on a framework, um, that I don't control or as you know, or maybe not stamped with an approval, but it gets very good, like prisms. Amazing. Mvvm cross is great too, but I didn't want to go all in just for this little piece of functionality where I'm like, oh, I could just write that myself or grab something where I was against some of the stuff because it wasn't built into the framework. And I always thought that these bigger ones did more than that, which they went off and they started doing all of the other things such as constructor injection and these other kind of high level or a kind of high level crazy abstractions where you weren't really sure where the code was going, where he could run into issues. So I tried to keep it simple and I think that's where some of my mind may have been changed as of recent frank. Frank: 14:55 Yeah. Um, I don't want to pick on any of these, but no, I take that back. I'm going to totally pick on math if just for a few minutes though. Um, I have a little experience with it. When you build visual studio extensions, you're almost always dealing with math. Uh, um, what does it stand for? James M e f what are we saying? The Microsoft extensibility framework. Oh Wow. So that's what it means. James: 15:20 No, actually, I don't know. The managed extensibility framework. Meth, Frank: 15:25 you were very close at first time work. Yeah. Um, and I always had trouble with it. It can never find my assemblies. The logs it produced were very, uh, I couldn't find them. I didn't know how to use them. And so like you would try to create an object and be like, Haha, I can't create the object. And you're like, but why? But why math? Why won't you create the object? So I think, um, as I said before about the graph and you have to detect loops and all these things, it actually isn't easy to write these things. General purpose and are the devil really is in the details. How well do they log, you know, um, how well can you diagnose problems with them? And I think that that's, that's kind of what scared me off a bit from dependency injection too, was that I didn't want to deal with this crazy mystery of where are you looking for my objects? But I think in the mobile world where we have limited scope of assemblies as in like on Ios, I ship my app, would these assemblies I cannot add to that list. Um, it's, it's a more practical model honestly, because now it's a fixed set of assemblies. I know exactly what it's, where it's looking, what it's looking for and all that. But I also want to talk about that startup performance. James: 16:34 Take a little detour. Yeah, yeah. Go for it. And that was it. So there was these other concerns before I go into my new love and passion is, I think you're right there. My concerns were not only maybe, I don't know where things are coming from, like where code readability is, I like to call it, who's, where is this coming from? Just knew it up. Right. That's what I was, I just knew it exactly. But also, yeah, the startup time for a mobile application is very different than a web server or a desktop application where you're using a full 32 gigs of Ram and a crazy horse power. Right. That, that's what I always thought was yet the other mean negative part of it. Frank: 17:13 Yeah. A Web server starts up once and handles thousands of requests, millions of requests. So you don't really care about startup performance over there. But on Ios and Android we care a whole lot and I think, um, Xamarin forms has always gotten a little bit of flack for startup performance. It's not large, but it is scanning all the assemblies and looking for things. I think things have improved there too, where you can minimize what it scans for and control that. Um, but the fun thing is if you're using a third party won or you have your own whole big set of objects that you want to, you James: 17:50 can be very clever and do things like just knew it up from the beginning. You're your route, uh, objects, your root Ui and then asynchronous. Do like the assembly scans and you know, resolve all the dependencies and do that all in the background so you can still get a Ui up very quickly if you just knew it up as we say, you know, don't use the dependency service. Just knew the objects up yourself. Uh, and then leaves the eco scanned for everything and build that dependency graph. Yeah. Well I want to talk about sort of the new hotness that I've come to light, which won't be new for many people building asp.net apps. But let's first take a break frank and thank our amazing sponsor this week. Tellerik listen, the team over at tellerik progress over there. They're doing awesome things. They obviously have great controls for nearly any single platform out there, whether it's mobile or web or Xamarin applications, but they are building frank, the tellerik Ui for Blazer. James: 18:52 What blaze or it gets all the love. I love this. Tell me more James. Yes, well it's an early preview, but the teller Aqi for Blazer is going to give you a rich set of web Ui components specifically designed for blazers. Or you can run these puppies right in the browser giving you rich web interfaces rather than c sharp are in c sharp rather than Java script. So you can get these components and they've been built from the ground up with tight integration into blazer as it evolves. So you can get it today if you're using blazer. Now you're saying like, well I'm not writing Blazer apps just yet. Uh, what else can I do? Well, like I said, they have things for not only just web but for blazer and of course Xamarin, they have all sorts of amazing controls for Xamarin, Ios, android and UWP making your apps to look super professional and modern. James: 19:43 And of course they just released a brand new pdf, viewer control, new pub controls and a doc layoff controlled. Super Great. All compatible. The visual studio 2019 so go give that a look had over to tellerik.com t e l e R I k.com telerik.com thanks to tell her I progress for sponsoring this episode. A merge conflict. That is super awesome. Thanks telerx it's, it's great to see component vendors kind of doing bleeding edge stuff. That's awesome. Yeah, it's super great to see you just boom day one good to go. And Blazers aren't even out yet, right? It's just like, oh yeah. And we've got early previous like that's great. I'm going to need that stuff and it's good to see it. That's a good sign for Blazer. I think so. Um, yeah. Well I had mess around a lot with blazer but I had recently be recently been talking with the asp.net core team frank. And this is where the trouble started. You are betraying us. James W we went from the mobile and now you're talking to web developers. Scary. So it all started with signal are frank and I love signaler. Yeah. Okay. I where this rabbit hole began James: 20:49 and then it Kinda came down to talking about some signal our stuff and then talk about asp.net and then my good friend Glenn who do was in this tweet and Brady were together and, and Glen was talking about some new stuff he was working on, which I can't talk about. I was like, that's really cool. I don't know if it really applies to mobile. And he goes, but does any of this other stuff apply to mobile? And I go, oh, I don't know. And I said, you know, one thing that I've loved about asp.net core, and maybe you hate it or maybe you love it, is with asp.net core. They really force you all. You're all in on this thing called like web hosts, this host builder type concept where asp.net core, everything is going to be handled for you. Logging, dependency injection configuration, ACDP clients. It's just going to do it all for you. Frank, you're, you're familiar with this concept. They're all in. Frank: 21:40 Yeah. For sure. Um, and this come with core. I think it did and how I think of it is configuration in code. Instead of having very complicated Jason files of do this, do that, you set up your services, you declare your dependencies and you do that all in these kinds of like startup or I guess their configuration files. I forget what they call him and Tyler and programs cs or startup cs, but all you're doing is basically informing some system that here are all the services that I want to use. Here's how to configure ohm, here's how to create the dependencies. Now we can also still have configuration files, but mostly the idea is configuration and code. You are creating declaring that dependency graph and code. James: 22:24 Yeah, and it's pretty nice. I would say overall it's like here are my controller's, she has my routing. Here's the things I want to add. So you can say, you know what to this app at MVC and add swagger support and add logging and add HTSP client factory for instance, and http client factories where this conversation began because a http client factory, you might be able to describe it better, but http client does a bunch of stuff and also allows you to handle like caching and retries and logging and all this stuff extra. But http client factory, which is part of asp.net and part of this hosting configuration just does that all for you. Is that correct frank? Frank: 23:10 Uh, yeah. Uh, but I think that there are even bigger performance benefits to it than just that. And this is something I learned on food get and it was actually a PR from someone and I didn't know this and I learned it in the PR and actually had to ask them to explain it to me. I think my first comment was, wow, this is a lot of code. What, what the heck is this for? Okay. So the idea here, and this is where my confusion came from, we have this object or this class called HTP client and that's what we do to go talk to a server and all that. And coming from kind of the database like the ado.net world, I just assumed the http clients pooled connections and did fancy stuff and all that. Like I thought I could just knew up 8,000 of these and it would just be intelligent about how it allocated sockets and all of that. Frank: 24:02 Well it turns out it's not. HCV client is basically going to open a socket for everything that you do with it. And so the real way that you want to get, um, connection pooling is to use the factory. What was it called? HTP client factory or just HV factory, I think. Http client factory. Yeah. Okay. Yeah. So the trick is you want to use that puppy and whenever you want a client you just ask it for a one. And that way it can actually do proper connection pooling. And this was super nice. Um, it meant that, um, it turns out, forget.org does a lot of http requests. That's basically what it's spending all its time doing. If you ever get a slow page load, just know that it's downloading half of the Internet in order to render that page. And so I think it was good because, um, you can easily run out of resources if you don't use connection pooling. James: 24:58 Yeah. And, and as I, that was the main question I had for Glen, as I said, you know, one question I get all the time is how can I use that in my mobile apps because that seems pretty good. Yeah, Frank: 25:08 yeah, for sure. Um, we, we definitely need that and our mobile apps. So in the past I would just use Apple Api Apis, but obviously that's not going to help you if you're on android or UWP. James: 25:21 Yeah. So I'm like, I want all of this stuff that is asp.net is getting, how do I get that? And he goes, oh, that's interesting. It's like we have this thing called the generic hosts builder and I go, okay, what do you mean? He's like, well, asp.net has a web builder. And there's this thing called the generic hosts builder as part of a magical library called Microsoft extensions hosting. Frank: 25:46 Hmm. Oh, right. So we were talking about this a little bit before and you gave me a little bit of background and the most interesting thing that I found was you told me that this is basically what I thought was asp.net code. All of this service could figuration all that. You're like, no, dude, it's actually just a dotnet standard library. You can use this anywhere. James: 26:09 It totally is. That's what the, now I will say that I'm not 100% sure if it's perfectly out of the box going to work amazing for every little thing, which I've been doing a lot of testing and it almost does, but there's a few quirks in mono, but, um, for Ios and Android, but we've, I think I'm going to be really working with Glen to smooth this over. But here's the cool thing about host builder is that it's just a dotnet standard library. It's sort of like all of the cool crazy things that, uh, asp.net gets, but without having that dependency on asp.net so it says that, uh, that in general, it's decoupled from the entire http pipeline that web host provides, but it gives you things such as configuration, dependency, service and logging. Now it does say in general in the documentation that it isn't suitable for web hosting scenarios because you'd want to use web hosts. James: 27:09 Well, I'm a mobile APP, I'm not web hosting, so this is going to be great. So we started to experiment with this and I'm going get hub, you can find a bunch of my little projects recently that I've been pushing code to. And I said, well, can I use this? How do I get HTP client factory into my app? And Glenn and I figured out that, well, how it works is you have to create a host builder, configure your service, add the http client factory nougat package and use dependency injection and constructor injection to actually get it to work. Because to the dark side, it was a given. You have to give in to the dark side to get it. And I said, all right, Glenn. All right, let's give it a go. Uh, I've a story. He said, let's go. He said, if you want it, you got to go this route. And I said, oh, I really want it though, right? I want to be able to get access to that. And he said, you know, you can't knew it up. You got to go this route. Frank: 28:10 You can't do it up. No. Uh, I want to paint a picture. I hope a lot of listeners have seen kind of like your boiler plate asp.net configuration. There's always just a few lines that always make it there. And so when you first showed me this code, um, and, and I looked at the initialization, I'm like, are you running a web server in here? Cause it looked like you were running is fee.net. And I'm like, why are you running is d. Dot net and a mobile app? This makes no sense. And you're like, no, dude, it's just the configuration stuff. And then, and that's pretty cool. Uh, so you're doing a few things. You're setting up your dependency graph. You have just one service I think so far. Um, Yup. And then you set up logging because we all need a logging abstraction. We're all tired of console dot. Rightline it, it's great at first, but eventually you want to persist those logs and do fancy things. I am sad to see that you had to disable console colors in your log. Yeah, it's tragic. James. Tragic. I know. What are we going to do without console colors? James: 29:13 Well, you know, I visual studio visual studio for Mac don't support it. So what's wrong with them? That is a problem that needs to be fixed. I think I need to put in a, you need to get that. Frank: 29:24 I think it's a little issue. I'm not sure if the ios logger, which is what Xamarin uses, I'm not sure if that supports it. So like that it might not even be worth it. They might have to do some nasty hacks. Uh, but you set it up and this is another interesting part. So I said that a lot of this is your configuration via code. So you can do like have if statements and all that. You could actually have logic setting all this up. But you also load a Jason file. James, explain yourself. James: 29:53 Yeah. So in in the normal asp.net route, they have the ability to set some default properties for either development or production such as you know, configuration keys or other properties. And maybe you want to have in development mode, use these logging settings. So what's cool is that when you load this, they call it a host configuration. This host configuration looks for a bunch of default keys. So one of the keys that I have inside of here is environment and it's called a development. But there's a logging and that logging will tell it to log everything cause I'm in development. I mean you can change those things. Those are, those are the ones that the system looks for. But you can add any random key. So I have hello world and you can load this Jason File and it will then override the defaults of if it's the key that it recognizes a or it will just add those key values into a dictionary for you that you can use at any time. James: 30:56 So that's nifty where you may want to have some keys or you want to have some specific, you know, um, true or false values. You don't want to hard code and maybe you want to swap that out at build time for instance. You can do that. So I load this configuration and since I load the configuration and I'm telling it that it's development, there's this really cool thing called that a called hosting environment. So once I load the host configuration, I have access to this hosting environment and then I can say, am I in development and I in production. And then I don't have to write my own custom logic to determine what values to use, you know, for all intensive purposes, which is kind of cool. You don't have to use it, but it's there anyways. Frank: 31:43 Yeah. I like this a lot though. Um, I think that's one place where the, the web programmers are actually beating off the little bit as they do have a very distinct concept between Dev environments and release environments. And so this coming from the web world, it's pretty hard baked in this concept of being able to split the world up like that or change things out. And I appreciate that because what I currently do right now is if I want to split those two worlds is I rewrite text files during my build process and it's nasty and ugly. And so this is nice because it's a more formal system. It's kind of a proven system. They'd been working with it for a long time. And so I, I'm actually pretty excited by it. You know, the funny thing is I'm realizing like these are all pieces that you could have accomplished yourself. Like you can do different solution configurations and in your project file you can have conditional logic to include this or that and change property values. But that stuff is all outside of code. And this is in code. And I think that, I just love the elegance of it. Again, it's configuration in code, it's, it's more controllable. It's more magical. Honestly, James: 32:55 it's, it truly is like, and that's what sort of won me over as I was writing the code. It's like, okay, I'm going to configure this host, I'm going to add a Jason file to it. I'm going to configure my services. How am I configuring it? Well, I'm going to add the http client. I'm going to add a Singleton, I'm going to add another singleton, I'm going to configure the logger and then I'm going to build it. And then now that I can figure it everything, I build it all up in a builder pattern and now I have a bunch of services I can access and I'm like, oh, that's cool. You know? You're like, oh, that makes some sense. And in what you could do here in the world of in mobile is you could have a conditional to say if debug load the development APP settings, if release, use the production settings. Right? You could easily do that. But that's all in the code where you're saying these are the settings and I'm going to be using it from that Jason File. But the rest could be the same because that Jason file will tell you if you are in development mode or in production or things like that. So that's actually super, super duper nifty. Yeah. And as, as I started going down, it just made it really nice and easy and readable like you said. Frank: 34:06 Yeah. And I, you were just making me think of another advantage to this having a in code and with logic is you can do hardware and capabilities detection. So if you're on Ios, it's pretty easy to tell if you're like an iPad or an iPhone. But after that you're using a lot of different API API APIs to go discover functionality. Does this phone support this or not? And you can do that just one time and set up different services for your different things. And so I liked that capability also of having that in logic. Just a runtime thing. And this is stuff you can't predict at compile time. James: 34:42 Yeah. And in fact, you may have something that is compatible with only newer versions of Ios. So you might have to configure a service that is my older compat facetime, you know, library or you know, geolocation library. And then here's my new version. And then you would, you could detect that here and configure it accordingly. Instead of Gobbly Gook, ring up a single file with am I on this thing, then do this thing and then do this thing and then do that thing. So that might be another advantage to writing it in this in this way. Yup. Frank: 35:15 And I guess he could apply that to platforms to now I see why everyone kept yelling at us, but I think, okay, so, um, we keep saying singletons but there's other options too. Um, we can, you can register transient services. And these are funny because it's not a global object. Every time you request a service it's to give you a new new object. So that's nice because, um, global objects are fine until you start modifying global state. And then you have race conditions and then you have locking. And so, you know, singleton, should it be used with care. I really do believe that just because no one knows how to do proper threading, literally no one. So it's an impossible task. And I think, um, if you start putting singletons all in your code, uh, it really limits your capabilities for doing multithreaded stuff. And so I actually do prefer to a side on the transients, new objects for every dependency. Frank: 36:15 But it's a pro, it's a perf thing. It's a correctness thing and you have to judge that on your own. Well, and I started to go down this route and I said, okay, well the nice thing here is all register. My main view model as you know, as a Singleton, which it should be a transient actually, but I will take into the constructor and I log or in this I http client factory. And since everything is all in on this, I now get all of that stuff for free. So I get the logger, I get the HDB client, and since I'm using the logger and I'm using the EAC to be client builder, the cool part here is automatically, because I'm doing all of this and it all gets figured out. Some magical way for me is whenever I make restful service calls or anything with that http client builder class at that factory, it automatically starts logging things to the council about what calls I'm making, how long is it taking, and all these different things. Frank: 37:11 And I'd have to write any code because it's reusing all of this tech and libraries that are packed into asp.net core applications. But inside of my Xamarin APP like mind blown. Okay. Yeah, that's pretty cool. Uh, anytime someone gives me free logging, I'm going to take it because it just makes debugging so much easier. Isn't it funny how we always, we rely on logs still to this day and I just love the, as he said, um, there's a little bit of magic here, right? Because did you know that that library is the blogger interface? No, but it Kinda didn't matter. It's a black box, let's not think about it. Uh, but that does raise a little issue that I have is discoverability. Uh, now if you get that package, Microsoft, that extensions, that hosting that, I get that right? Yup. Yup. That comes with a bunch of stuff that came with blogging and that came with the service provider itself. Uh, but then you had to add another package. Um, Microsoft that extensions not http, I believe. Yes, yes. Yeah. So the trick here is there's not great ide help here to say like, oh, what other services are out there that I can just go download off of new get. Oh boy had just started a new food get feature, start listing all the new guests that actually have these extensions. There is that, yeah, there is that discoverability problem James: 38:36 right now. At least it's true. You know, I started to talk to Glen, he was like, yeah. The Nice thing here is that there's so many different configurations, different extensions that are written by leaving that community. Like I said, there's a poly one, there's like a refit one. There's all these other ones that are out there. Um, because they fall into this model and then you could technically technically use them. Now, some people could be creating extension specifically for asp.net and they may not work in Xamarin world. And I've, there's a few quirks with it, but for all intents and purposes, it does actually work. Um, I think that's relatively cool in general because I thought, well, what else could I do with it? Right? Which is, I've already made it. So this log or an http client, they're kind of magical. Like, what if I to put all of my pages into the single Tanner transient model, right? James: 39:28 Like don't even put my services or put my main view models. Why don't you go all the way up the stack and why don't you just put the entire app into it? Yeah. So I did, that crosses a line for me a little bit, James, but I get where you're coming from. And the reason you did this is because your Ui object uses these resources. Technically your Ui object could have just had a view model and the view model could have used the resources, but then your view models more of a controller, not so much a view model anymore. So it's just like, where do you want to draw the line? And you drew the line at my main page uses these services, therefore I need someone to provide these services. Therefore my main page is now a service. Yes, it's a little viral. We could say in the same way that a in a way is viral, like you put it into one function now, two functions now for functions. James: 40:21 I think, um, very quickly people's code turns into I everything, every class is, I sometimes I'm like, but where's the code that does stuff and they're like, well that's in the eye. Does stuff class. That's true. Yeah. The, you know, I, I started down this path and I thought it would be a fun experiment today. Just Cook. Can I do it? That's what I wanted to see. Can I do that? And I could do it now. What? I actually do it. No, I don't think I would actually know. Oh, come on, wait, wait. You just ruined the whole episode. I'm fully on board here and you just throw that out. You're not going to do it. James convert? No, not to full APP. Not the full app and not the whole thing. I'm really on board with quite now. I think I'm now a little bit more on in on for the constructor injection, but only because I'm configuring the services that go into it. James: 41:15 So I'm, I'm not passing around a bunch of other services, but I'm like, I controlled these services so I want this to work this way. And so I'm not, I, I'm indecisive frank. I don't know. It's a full forward man. Don't look back. I love everything that I did and I'm, I'm still not sure if if I'm like, I want to use this all the time or not type of thing, but I'm pretty amazed that it, it just worked. You know what I mean? And I'm pretty sure that I'm probably gonna have to like present this at build or something cause it's super Frank: 41:50 cool. And every asp.net developer, every prism developer rolls their eyes and Eunice. James: 41:57 That's true. That's true. It only took me 145 episodes people, but we did it. I'm on board. Frank: 42:04 Ah, I can't wait to read your code from now on. It's going to be, I does this. I does that. I did it. That I think, I think that's my little glass complaint is my level of laziness where I'm like, Oh man, I got to type out the part in the interface and then go to my implementation class and type that part out. What is the c plus plus? Do I have header files now? I thought I was using something without Hetero files. It's true. Yeah. Uh, so it's, yeah, I should stop worrying about how much time I'm wasting typing and focus more on architecture. But you know me, I don't like to over engineer and sometimes it feels a little bit like over engineering. James: 42:43 Well, the Nice thing is that you could pick and choose with this model, right? So you don't necessarily have to use the constructor injection. What you could do is you could just get the service provider and then you can just say, give me the service, Frank: 43:02 you know, um, actually let's call that out for just a moment because it actually caught my attention. We keep talking about this service provider as if there's only one of them, but we have a little chicken and egg scenario. Where does the service provider come from? If we have this thing with all these global objects? Well, who's hanging onto those who in control of it? That's the surface provider. And I saw that in your application. You literally created a public static as a global variable, public static I service provider service provider. And that means that defend yourself, James. Now James: 43:38 where else are you going to put it? It's in the APP. You got to put it somewhere. Frank: 43:41 Yeah. Yeah. Uh, so, but that just gets to the point of you do have this rooted thing. So technically you can have multiple service providers and things like that. You can create different branches. I don't know if there are any benefits to that, but I liked that, um, the, um, framework itself for these libraries, whatever we want to call them, they don't have that global variable. It's still up to you. So you get them, make the decision of who can see it, who can control it and all that. I do like that part. So you're not stuck with their choice. Yeah, James: 44:12 that's very true. And this is all very much experimental for me. Mostly because I wanted to get the http client factor. That's all I really wanted. Frank, at the end of the day, I'm going to give me this, so we'll see how I go, but I will, I now going through this experiment gave me a really good, um, James: 44:32 understanding of how asp.net core works better. So one th one takeaway, even if you're not building mobile apps, maybe you're building a, a Dinette Corp counsel application or any, any other application is you could give this a try and I'll, and I'll put a link to my, my, my, it's called all extensions. That's what I, that's what I call it, my good hub repo. You could give this a try and any application and just sort of tested out to understand this model of development, uh, if you're new to it. Because the one thing that I've always said, a lot of people say, well James, why don't you use prism and why don't you use or Mvvm light and why don't you use these other things? And I go, the reason I don't use them is because it's not part of the frame. It's not in the box. And a new developer coming in looking at my code has to go now learn a whole new thing. Frank: 45:27 Yeah. Yeah. And it feels I, when Microsoft has a library, I get you, it feels so much more official, feel so much more taken care of, but we should point out that this is Microsoft dot extensions, not system dot extensions. So it's definitely still a Microsoft control thing and is not a part of the framework per se. That said, I think everyone that sees Microsoft dot and it's like, wow, it's a part of the framework. Yeah. Especially if it's a.net standard library and it's a the licenses Apache. So pretty much open source. Yeah, pretty much open source. So there you go. It's not too big. If I can say one more thing that I've never liked about these libraries. I think one of our things is like, I don't want to pull in two megabytes of code for dependency injection and I don't know what this thing totals too, but it's just like five or six little 30 kilobyte assembly. Frank: 46:16 So it's not big at all. It's nice and probably linked out. If you're not using all the stuff, Bingo. Bango should be good. Yeah, it's tricky for this that they all use reflection. That's always tricky to a link out. All these dependency injectors. Another complaint of mine. That is true. I'm very curious how it works with the, I've only tested in and debug, so I haven't tested it with or without the linkers. I'm very interested I should say about how that works. So again, yeah, just find a bunch of stuff you'll most likely want to set your app to not link out your own code. At the very least, I think the library could survive it, but definitely not your own code. Yeah, totally. Oh yes. That's very true. Yeah. Where, where does that code come from? Who knows? It's gone. The linker says you weren't using this code, so your whole class is gone. It boots up to a white screen. How lovely. That's lovely. Thanks linker. Alright, well there you got then blogging, James. Good logging for that. James: 47:18 Got good logging and that's all that matters. So cool. All right, we Frank: 47:22 did it. We did what? A milestone. So now we're going to get all the tweets. Okay everyone please tweet us, make sure you, you James: 47:30 make James pay for 140 something episodes of bashing defendants injection and then that's doing this episode. It's very true. People are going to either love or hate this episode if you loved it or hate it or just want to make fun of me like frank side. Go ahead and tweet at us. Merge conflict. FM. You tweeted me directly at Jane's Mountain Magno at Pra. Clara, I'm over there. Uh, you can of course follow the show on the internets@mergeconflict.fm or check out, um, any of your favorite podcast app seems hit subscribe, tell your friends about it. It's good. People like to show we love you. I love reviews. We get those, which is super duper Rad. Um, and we like to read those back. So if you're around, you want to give us a little love, give us a, give us a little review. We would love that, but I think it's going to do it for this week's dependency injected podcast. Frank & James: 48:20 I'm James Montemagno & I'm Frank Krueger. Thanks for listening.